Texture cleanup after destroyEntity

Minor issues with the Ogre API that can be trivial to fix
User avatar
so0os
Bugbear
Posts: 833
Joined: Thu Apr 15, 2010 7:42 am
Location: Poznan, Poland
x 33

Texture cleanup after destroyEntity

Post by so0os »

I'm positng it here, since I'm not sure what to make of it.

When I was destroying entities, I thought it textures would get destroyed as well, but I ended up clogging up my GPU mem.

Is unloading unreferenced resources necessary to clean the textures? I wasn't loading the textures and materials explicitly, but I need to get rid of them myself. Thus, I suggest documentation notice on 'destroyEntity' method.

Also, unloading unreferenced textures didn't help as well, because they were referenced from material's TextureUnitStates. So I needed to do this tlike this:

Code: Select all

// DESTROY ENTITIES, AND THEN...
MaterialManager::getSingletonPtr()->unloadUnreferencedResources(true);
TextureManager::getSingletonPtr()->unloadUnreferencedResources(true);
Or perhaps I'm missing something obvious?
Sos Sosowski :)
http://www.sos.gd
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58

Re: Texture cleanup after destroyEntity

Post by CABAListic »

This is expected and intended behaviour. An Entity is just a visual instance of several resources, namely Meshes, Materials and Textures. Said resources are implicitly loaded when constructing the entity (if they aren't already), but they are not implicitly released. In fact, it would be disastrous to do so, because often you will create and destroy several instances (Entities) of those resources, and if at each point you would have to load the resources all over again, that would mean freezes in your game during the resource loading.

So yeah, if you actually don't need the resources anymore, you need to explicitly tell Ogre.
User avatar
so0os
Bugbear
Posts: 833
Joined: Thu Apr 15, 2010 7:42 am
Location: Poznan, Poland
x 33

Re: Texture cleanup after destroyEntity

Post by so0os »

Thanks, case closed!

EDIT: But still, I suppose this should be documented.
Sos Sosowski :)
http://www.sos.gd