How to correctly load and unload fonts at run-time?

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
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

How to correctly load and unload fonts at run-time?

Post by greenya »

Hello!

I need to load and unload fonts at run-time.
I write next:

Code: Select all

#include "../irrlicht-trunk/include/irrlicht.h"
#pragma comment (lib, "../irrlicht-trunk/lib/Win32-visualstudio/Irrlicht.lib")

using namespace irr;

void main(int argc, char** argv)
{
	IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2du(720, 480));
	gui::IGUIEnvironment* guiEnv = device->getGUIEnvironment();
	
	gui::IGUIFont* font = 0;
	
	font = guiEnv->getFont("../irrlicht-trunk/media/fontcourier.bmp");
	guiEnv->removeFont(font);

	font = guiEnv->getFont("../irrlicht-trunk/media/fontcourier.bmp"); // Access violation reading location 0x00000000.
	guiEnv->removeFont(font);

	device->drop();
}
Second getFont() for the same font file name leads to unhandled exception and debugger points me to CGUIFont.cpp to line 318:
315: if (c == colorTopLeft)
316: {
317: image->setPixel(pos.X, pos.Y, colorBackGroundTransparent);
318: SpriteBank->getPositions().push_back(core::rect<s32>(pos, pos));
319: }
SpriteBank is null there.

Thanks for any help!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ok, I messed that up. Unfortunately there is no real good solution for this until we fix reference counting for textures. So the new solution I'm going to check-in in a moment will just prevent the crash and should at least allow to re-load a font. The rest has to wait until we no longer allow direct texture-access in materials I guess.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Now i'm keep getting into my console just after createDevice() call:
Could not load sprite bank because the file does not exist: #DefaultFont
Example in first post works without crashes.
The memory doesn't really freed by removeFont(), i see this after loading and unloading the font about 20 times (memory usage only grows up).

P.S.: this is after changes made in svn rev. 3600.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Yeah, I know about the warning, couldn't figure out a quick way to get rid of it. And yeah - texture memory can't be released. It's simply not possible in a clean way in the current system and I don't think I can change that until we have materials with reference-counted textures. The only thing I fixed is the crash and that it might now be possible at least to re-load a font-file. I guess adding the removeFont was a bad idea at this time and I shouldn't have done that. Maybe I should just kick it out again.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply