how to remove and re-set IGUIFont?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
nixx
Posts: 22
Joined: Thu Jan 18, 2007 5:00 am
Location: Yogyakarta, Indonesia

how to remove and re-set IGUIFont?

Post 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 :).
linkoraclehero
Posts: 81
Joined: Sat Sep 09, 2006 6:46 am

Post 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 ;)
nixx
Posts: 22
Joined: Thu Jan 18, 2007 5:00 am
Location: Yogyakarta, Indonesia

Post by nixx »

irrlicht's bug or my bug?
I'll try your code. :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
nixx
Posts: 22
Joined: Thu Jan 18, 2007 5:00 am
Location: Yogyakarta, Indonesia

Post 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.
nixx
Posts: 22
Joined: Thu Jan 18, 2007 5:00 am
Location: Yogyakarta, Indonesia

Post by nixx »

OK, I solved it. I forgot to drop the pointer of irrlichtDevice.
Thanks :)
Post Reply