not sure it is really the right place here to do this but I think it is an annoying problem that could be easily fixed.
Irrlicht is using full memory management with image texture loading, meaning that you are not supposed to care about allocation and deallocation of your textures. The problem is that if you really need to manage yourself the memory and delete a texture at a given moment it becomes really painfull to do this.
For example suppose you use a spritebank to manage a list of icons for a listbox. You want to flush it completely : remove all textures definitly and generate new ones. You will face a big memory increse if you simply clear the spritebank, because the reference count of your cleared sprites will be 1 because they are stored in the engine. Now suppose your new list is filled with big images and a large amount of it, and you flush it for the 4th time : you get a crash on a new and suddenly realize that your app is greater than 1.9GB in the ram... Hell !
And the only way I found to do what I want to do is to do something painful like this :
Code: Select all
// remove textures from the engine because we want to delete them now !
for(u32 i = 0; i < bank->getTextureCount(); ++i)
{
Texture* tex = bank->getTexture(i);
driver->removeTexture(tex);
}
bank->clear();
Code: Select all
#define SAFE_LOAD_IMAGE(driver, image, path, usePremultipliedAlpha) if(!image) \
{ \
image = driver->getTexture(path); \
if(image) \
{ \
image->grab(); \
driver->removeTexture(image); \
if(usePremultipliedAlpha) \
PremultiplyAlpha(image); \
} \
} \
#define SAFE_UNLOAD(res) if(res) \
{ \
res->drop(); \
res = NULL; \
} \