[fixed]removeAllTextures and loadScene crash

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
lion
Posts: 12
Joined: Wed Dec 10, 2008 1:34 pm

[fixed]removeAllTextures and loadScene crash

Post by lion »

I made a simple example with loading scene from .irr file (terrain.irr from irrEdit 1.5). When i try to reload scene the example crashes:

Code: Select all

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;

void init()
{
        driver = device->getVideoDriver();
        smgr = device->getSceneManager();

        smgr->loadScene("scenes/terrain.irr");
        smgr->addCameraSceneNode(0, vector3df(0,330,40), vector3df(0,5,0));
}

int main()
{
   device = createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16, false, false, false, 0);

	init();

	int k=0;

	while(device->run())
        {
                k++;

                if ( k%100 == 0 )
                {
                        smgr->getMeshCache()->clear();
                        smgr->clear();

                        driver->removeAllTextures();  //crashing because of this line

                        init();
                }

                ///////////////////
                driver->beginScene(true, true, SColor(255,100,101,140));

                smgr->drawAll();
                
                driver->endScene();
        }
        device->drop();
        return 0;
} 
Problem is in the line driver->removeAllTextures(). Without this line the example works fine.

linux, irrlicht 1.5

gdb:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7ab18e0 (LWP 22106)]
0x080ed281 in irr::video::COpenGLDriver::setTransform (this=0xa344b70, state=irr::video::ETS_TEXTURE_0, mat=@0x8318280) at COpenGLDriver.cpp:693
693			const bool isRTT = Material.getTexture(i) && Material.getTexture(i)->isRenderTarget();
Any ideas?
Last edited by lion on Mon Mar 16, 2009 1:44 pm, edited 2 times in total.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

I'm guessing that your .irr file is trying to use a texture that isn't there after you clear them all. Or maybe there's a material class floating somewhere that's trying to use a texture that's gone.

Quoted from the API:
virtual void irr::video::IVideoDriver::removeAllTextures ( ) [pure virtual]

Removes all textures from the texture cache and deletes them.

This method can free a lot of memory! Please note that after calling this, the pointer to the ITexture may no longer be valid, if it was not grabbed before by other parts of the engine for storing it longer. So it is a good idea to set all materials which are using this texture to 0 or another texture first.
lion
Posts: 12
Joined: Wed Dec 10, 2008 1:34 pm

Post by lion »

I think I do not understand you quite.

For example I load .irr file. Than I want to remove all i've loaded (nodes, materials, textures etc.) and than load .irr file again. So

Code: Select all

smgr->getMeshCache()->clear();
smgr->clear();
driver->removeAllTextures();

smgr->loadScene( fn )
So i think this process should not depend on .irr file because irrlicht must reload everething.

May be my "removing all" part is wrong?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

did you try to clear the scene manager first and then the mesh cache ???
it could be that clearing the mesh cache doesn't remove all meshes, because they are still in use by the scene manager... ;)

Code: Select all

smgr->clear();
smgr->getMeshCache()->clear();
driver->removeAllTextures();

smgr->loadScene( fn ) 
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Re: removeAllTextures and loadScene crash

Post by vitek »

lion wrote:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7ab18e0 (LWP 22106)]
0x080ed281 in irr::video::COpenGLDriver::setTransform (this=0xa344b70, state=irr::video::ETS_TEXTURE_0, mat=@0x8318280) at COpenGLDriver.cpp:693
693			const bool isRTT = Material.getTexture(i) && Material.getTexture(i)->isRenderTarget();
Any ideas?
I don't have access to a debugger or compiler at the moment, just the source, but this appears to be a bug. The Material is the last active material, which may have pointers to textures that were unloaded in the removeAllTextures() call. The scene manager could easily clear the material before returning from clear().

As a workaround, you can do it yourself. The following should resolve this particular issue.

Code: Select all

  smgr->getMeshCache()->clear(); 
  smgr->clear(); 

  const video::SMaterial m;
  driver->setMaterial(m);

  driver->removeAllTextures();
Also, if you are posting debugger output, the most useful thing that you can do is to provide a stack trace. You can get this with the where command when using most command line debuggers like gdb.

Travis
lion
Posts: 12
Joined: Wed Dec 10, 2008 1:34 pm

Post by lion »

2Acki:
yes i tried. three variants:

Code: Select all

smgr->clear();
smgr->getMeshCache()->clear();
driver->removeAllTextures();
/////////////////////////////////
smgr->getMeshCache()->clear();
smgr->clear();
driver->removeAllTextures(); 
/////////////////////////////////
smgr->getMeshCache()->clear();
smgr->clear();
smgr->getMeshCache()->clear();
smgr->clear();
driver->removeAllTextures(); 
example chashes in each variant.

2vitek:
you are right! your method works perfect. problem solved. thank you.

Thanks everyone for help!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

This topic should probably be moved to the Bug Reports forum. IMO, it is a bug in the implementation.

Travis
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

ahh, after reading Travis' "workaround" I see the problem... :lol:
well, my base idea was right, something was still in use...
good to know this if I ever run in the same problem... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply