Page 1 of 1

how to remove and re-set IGUIFont?

Posted: Sun Jun 17, 2007 4:28 pm
by nixx
In my application, I create irrlicht device at least twice : the first is using the Null Driver to detect the monitor configuration, close it, and create it again using the more appropriate configuration. The device can be re-created later if the user wants to change the configuration.

The problem is, the memory usage increased each time I re-create irrlicht Device. I found out that the font objects and textures have not been removed. I can remove another texture using the method removeAllTextures() in IVideoDriver, but I can't remove the font texture. How should I solve it? Is there a way to remove the texture being used by an object of IGUIFOnt? Or can I set the previously loaded font texture to the new re-created GUI skin?

My code is below.

Code: Select all

void CGameManager::init()
{
	irrlichtDevice = createDevice(driverType, screenSize, depth, 
		fullscreen, shadows, vsync, 0);
	irrlichtDevice->run();
	irrlichtDevice->setEventReceiver(this);

	// the problem is here. They are all gui::IGUIFont
	font = irrlichtDevice->getGUIEnvironment()->getFont("resources/images/fontgaramond12.bmp");
	fontLabel = irrlichtDevice->getGUIEnvironment()->getFont("resources/images/fontgaramond12.bmp");
	bigfont =  irrlichtDevice->getGUIEnvironment()->getFont("resources/images/fontgaramond18.bmp");

	
	if (!font)
		irrlichtDevice->getGUIEnvironment()->getSkin()->setFont(font);
}
This is how I use the method.

Code: Select all

irrlichtDevice->closeDevice();
init();
Thanks for your help :).

Posted: Sun Jun 17, 2007 11:55 pm
by linkoraclehero
Seems to me like a bug in the code. Irrlicht normally manages EVERYTHING that's created. I think you can destroy any object by it's pointer, maybe with either:
delete &font;
or
font->destroy();
But don't quote me on this ;)

Posted: Mon Jun 18, 2007 7:58 am
by nixx
irrlicht's bug or my bug?
I'll try your code. :)

Posted: Mon Jun 18, 2007 9:06 am
by hybrid
Why do you check for (!font) and use this null pointer for setting the new font? What happens if you get a font?
Anyway, I assume that you have to drop the pointers once you don't need them anymore, otherwise they stay in the cache.

Posted: Mon Jun 18, 2007 2:44 pm
by bitplane
hmm if you dropped the device then the fonts should be destroyed along with the gui environment, and all the textures should be removed with the video driver. if this doesn't happen then it is a bug

Posted: Thu Jun 21, 2007 2:27 am
by nixx
I'm sorry for coming late,.I am a little bit busy lately.
hybrid wrote:Why do you check for (!font) and use this null pointer for setting the new font? What happens if you get a font?
Anyway, I assume that you have to drop the pointers once you don't need them anymore, otherwise they stay in the cache.
oops...I forgot to remove the (!font) part. I edited the code several times and forgot to remove that line. I'm kind of "afraid" to remove any classes in Irrlicht using delete, because I think there are always a method to remove object.
bitplane wrote:hmm if you dropped the device then the fonts should be destroyed along with the gui environment, and all the textures should be removed with the video driver. if this doesn't happen then it is a bug
I think I forgot to drop the irrlichtDevice. It's not enough to make use of closeDevice() only, isn't it?

Anyway I'll try to recode it. Thanks for all of your help.

Posted: Sat Jun 23, 2007 4:54 am
by nixx
OK, I solved it. I forgot to drop the pointer of irrlichtDevice.
Thanks :)