Cleaning up textures

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
Thomas_
Posts: 34
Joined: Mon May 08, 2006 1:51 am
Location: Corvallis/Eugene, Oregon

Cleaning up textures

Post by Thomas_ »

So I was told that manually deleting a scene node that you added with add___SceneNode or similar messes up the system. I understand this and have changed my code to fix using the remove() method. I was wondering however, does this apply to textures or can I just delete (ITexture* variable)? If I cannot delete textures, how can I clean them up at runtime?

Thanks!

-tom
Warchief
Posts: 204
Joined: Tue Nov 22, 2005 10:58 am

Post by Warchief »

bool irr::IUnknown::drop ( ) [inline]

Drops the object. Decrements the reference counter by one. Returns true, if the object was deleted. The IUnknown class provides a basic reference counting mechanism with its methods grab() and drop(). Most objects of the Irrlicht Engine are derived from IUnknown, and so they are reference counted.

When you create an object in the Irrlicht engine, calling a method which starts with 'create', an object is created, and you get a pointer to the new object. If you no longer need the object, you have to call drop(). This will destroy the object, if grab() was not called in another part of you program, because this part still needs the object. Note, that you only need to call drop() to the object, if you created it, and the method had a 'create' in it.

A simple example:

If you want to create a texture, you may want to call an imaginable method IDriver::createTexture. You call ITexture* texture = driver->createTexture(dimension2d<s32>(128, 128)); If you no longer need the texture, call texture->drop(). If you want to load a texture, you may want to call imaginable method IDriver::loadTexture. You do this like ITexture* texture = driver->loadTexture("example.jpg"); You will not have to drop the pointer to the loaded texture, because the name of the method does not start with 'create'. The texture is stored somewhere by the driver.

Definition at line 112 of file IUnknown.h.
You should never call delete (for any object allocated from irrlicht dll). Memory is allocated from dll, so your program does not own the memory.
Warchief's Warboard 3D Now hotseat release
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Yes, Warchief is right...
But you can "delete" a texture with removeTexture(...)...
But be sure the texture is no longer needed !!! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Thomas_
Posts: 34
Joined: Mon May 08, 2006 1:51 am
Location: Corvallis/Eugene, Oregon

Post by Thomas_ »

Thanks!

removeTexture is exactly what I wanted!
Post Reply