removeTexture crasher

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
MolokoTheMole
Posts: 109
Joined: Tue Jan 09, 2007 1:18 pm

removeTexture crasher

Post by MolokoTheMole »

removeTexture causes havoc with impossible to find memory bugs. Irrlicht seems to keep the removed texture in cache. I made a temporary solution by cleaning the last material state, by making a wrapper function:

Code: Select all

void SafeRemoveTexture( ITexture *texture )
{
	if (texture && video && driver)
	{
		video->removeTexture( texture );

		SMaterial clean;
		clean.TextureLayer[0].Texture = NULL;
		clean.TextureLayer[1].Texture = NULL;
		clean.TextureLayer[2].Texture = NULL;
		clean.TextureLayer[3].Texture = NULL;
		video->setMaterial( clean );
	}
}
However this needs to be placed in removeTexture( ); itself.
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, since we don't keep track of the texture usage for now it's better to fix the render state changes to properly clean out the textures. If the texture is still used even when no mesh or cache holds any reference to it there's something wrong in the state handling. Would need to debug the wrong setup phases, though. Any code?
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

hybrid wrote:Well, since we don't keep track of the texture usage for now it's better to fix the render state changes to properly clean out the textures. If the texture is still used even when no mesh or cache holds any reference to it there's something wrong in the state handling. Would need to debug the wrong setup phases, though. Any code?
wait is this what you uppers were talking about? i think i saw a thred somewhere takling about "better texture reference counting"?

i have not had any problems so far but just asking
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you use a texture in a certain material, and drop the only mesh that is using the material, it could be worth removing the texture as well. This would only be possible by using reference counting on textures, which is not yet done. But it would also change the way textures are handled, change SMaterial completely, and other things.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Well, there are many cases where you don't want to remove the texture when the mesh is removed. This should not be the graphics engine's call. A specific call to remove the texture from memory should be allowed though...

Not sure what Moloko means with "removeTexture causes havoc with impossible to find memory bugs.", however...

"Irrlicht seems to keep the removed texture in cache." <-- that'd be a significant bug if it were the case...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Unless there's a bug in reference counting in the texture cache, textures will be deleted after clearing the cache. At that point, also removal on the GPU happens. Otherwise it'd be indeed a bug. One bug that we have had in the past was that the texture was still bound in some variable (and thus also on the GPU) which caused crashes in the drawAll call. But that should be fixed for some time already.
MolokoTheMole
Posts: 109
Joined: Tue Jan 09, 2007 1:18 pm

Post by MolokoTheMole »

The program crashes when you start rendering after you removed the texture. It is nearly impossible to find this bug if you don't have the Irrlicht source code or don't know its inner working.

There was a thread here with a possible solution. I can't find it of course because of bad luck now. Maybe you remember, the guy simply suggested to clear the material cache on beginScene().
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I use valgrind, gDebugger and MSVC memory debugger and cannot reproduce such problems. Please post code which shows off the error so I can trace it down.
Post Reply