Hi Carsten,
Thank you a lot ! It worked like a charm...
Just added the addRefCP(aImgAnimation[i]); loop and bang ! There goes my 
animation !

Thanks again !

Patrick


Carsten Neumann wrote:
>       Hello Patrick,
>
> Patrick Perron wrote:
>   
>> Hi,
>> I have a problem with a texture when I execute my program.
>> I’m running VRJuggler 2.0.1 and OpenSG 1.6.0 on an SGI Irix system in a 
>> CAVE environment.
>> Here is what I want to do and what is happening (the source code sample 
>> will follow):
>>
>> I want to create a Plane geometry and apply a texture on it. The texture 
>> will be an animated movie (each frame is an RGB image), so I will change 
>> the texture each frame displayed (like doing a flip book animation).
>>
>> The problem I have is when I play all the animation once, it’s OK, but 
>> the second time, the program crash with this warning “WARNING: 
>> Window::frameExit: Caught stray OpenGL error invalid operation (0x502)”. 
>> I did some test and it’s really seems to be related to a texture 
>> problem. The problem seems to come from the image data either being 
>> deleted or something like that.
>>     
>
> you probably have no other references to the first image and when it is 
> removed its refcount is decreased and the image deleted.
> See below on how to fix that:
>
>   
>> Here is an extract of the code:
>>     
>
> [SNIP - some code]
>
>   
>> CScene::CScene()
>> {
>> GeometryPtr AnimGeo = makePlaneGeo(10,8,1,1);
>> tex_01 = SimpleTexturedMaterial::create();
>> for(int i=0; i < 10; i++) aImgAnimation[i] = Image::create();
>> aImgAnimation[0]->read("frame_01.sgi");
>> aImgAnimation[1]->read("frame_02.sgi");
>> aImgAnimation[2]->read("frame_03.sgi");
>> …
>> aImgAnimation[9]->read("frame_10.sgi");
>>     
>
> put a loop with this content here:
>
> addRefCP(aImgAnimation[i]);
>
> this increments the ref count of the images (in this case to 1).
>
>   
>> beginEditCP(tex_01);
>> tex_01->setImage(aImgAnimation[0]);
>> endEditCP(tex_01);
>>     
>
> without the addRefCP, aImgAnimation[0] gets a ref count of 1 here, the 
> other images remain at 0.
>
>   
>> beginEditCP(AnimGeo, Geometry::MaterialFieldMask);
>> AnimGeo ->setMaterial(tex_01);
>> endEditCP(AnimGeo, Geometry::MaterialFieldMask);
>>
>> NodePtr Anim_core = Node::create();
>> beginEditCP(Anim_core, Node::CoreFieldMask);
>> Anim_core->setCore(AnimGeo);
>> endEditCP(Anim_core, Node::CoreFieldMask);
>> // Master node of all scene already exist…
>> beginEditCP(MasterNode);
>> MasterNode->addChild(Anim_core);
>> endEditCP(MasterNode);
>>
>> }
>>
>> void CScene::ChangeAnimation(float fElapsedTime)
>> {
>> int iFrame = fElapsedTime % 10; // Frame between 0 and 10
>> beginEditCP(tex_01);
>> tex_01->setImage(aImgAnim[iFrame]);
>> tex_01->imageChanged();
>> endEditCP(tex_01);
>>     
>
> this is where the images are lost without the addRefCP. The image that 
> is being replaced has its ref count decremented, i.e. it becomes 0 and 
> therefore the image is deleted.
>
>   
>> }
>>
>> I did an other test too, I changed the way that ChangeAnimation(float 
>> fElapsedTime) was running, meaning that I was passing the exact frame 
>> number I wanted to be displayed… So, what I did is asked the first 
>> frame, then the third frame and then the second one… every frame worked 
>> as intended… But if I ask the first one, then the third one and finally 
>> the first one again… BOOM, the program crash ! I added finally one quick 
>> checkup, like checking the width of the image before displaying it: when 
>> asking frame 1, size is ok, the asking frame 3, size ok, asking back 
>> frame 1, size is now 0…Like if the info of the image have disappeared…
>>     
>
>       Hope it helps,
>               Carsten
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Opensg-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensg-users
>   

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to