Cleaning up ETM assets and reloading new ones

MisterMayhem

28-01-2008 00:57:55

My project is designed to load terrains, then clean them up and load different ones if necessary. I'm running into a problem where I can load the terrain fine, edit it and unload it. However loading subsequent terrains runs into trouble. the shadow map and splatting is left behind. The shadows and splat maps can no longer be changed either.

if an ET::SplattingManager instance constructor requires the dimensions, it seems logical that you need to create it and delete it when loading and unloading the terrain. The same with loading and unloading the light map. This way you can handle differing dimensions on subsequent loads.

When loading the terrain, I use the following code to set up splatting and the light map:
// create the splatting manager
mSplatMgr = new ET::SplattingManager("ETSplatting", "General", 512, 512, 3);
// specify number of splatting textures we need to handle
mSplatMgr->setNumTextures(6);

// create a manual lightmap texture
TexturePtr lightmapTex = TextureManager::getSingleton().createManual(
"ETLightmap", "General", TEX_TYPE_2D, 256, 256, 1, PF_BYTE_RGB);


To clean up the splat and light maps when unloading, I use the following:
delete mSplatMgr; mSplatMgr = 0;
TextureManager::getSingleton().remove("ETLightmap");


Has anyone else dealt with loading and loading terrain this way? The problems aren't present if I don't new and delete the ET::SplattingManager instance with each new map and I don't remove the light map texture, but then I'm stuck with the same texture dimensions.

CABAListic

28-01-2008 02:00:23

I don't follow; what exactly is the problem you're experiencing with recreating the splatting manager or the lightmap?

MisterMayhem

28-01-2008 03:22:24

After deleting the splatting manager and removing the light map, and then creating another splatting manager and light map of the same names, the calls to ET::createTerrainLightmap, blitFromMemory etc. on the texture named "ETLightmap", and the call to mSplatMgr->paint seem to have no effect on the lighting and splatting.

Also, the previous splatting and lighting are on the map, even after I made the calls to remove the light map and delete the splat manager from before.

I'm continuing to debug to see if I missed something, but I also wanted to confirm that it seems reasonable to delete the splatting manager, and make the call to TextureManager::getSingleton().remove("ETLightmap") to clean things up, and if that's how others are doing it.

CABAListic

28-01-2008 09:45:16

Hm, that would actually sound more like an Ogre bug, ETM keeps no memory of its textures used, especially not with the lightmap seeing as ETM doesn't even manage that one.
I currently have no time investigating myself, but I'd suggest you first experiment with the lightmap. Maybe Ogre still keeps it loaded somewhere. You could try to specifically unload the resource before removing it, maybe that helps?

kungfoomasta

28-01-2008 18:06:58

After you delete the terrain, use the Ogre TextureManager to unload any textures. Also use the MaterialManager to unload any materials. Recreate your materials and make sure its loaded (manually call load) and see if that helps.

I don't use splatting at the moment, so I'm just throwing out suggestions, sorry if they don't help.

SongOfTheWeave

29-01-2008 12:19:05

After deleting the splatting manager and removing the light map, and then creating another splatting manager and light map of the same names, the calls to ET::createTerrainLightmap, blitFromMemory etc. on the texture named "ETLightmap", and the call to mSplatMgr->paint seem to have no effect on the lighting and splatting.

Also, the previous splatting and lighting are on the map, even after I made the calls to remove the light map and delete the splat manager from before.

I'm continuing to debug to see if I missed something, but I also wanted to confirm that it seems reasonable to delete the splatting manager, and make the call to TextureManager::getSingleton().remove("ETLightmap") to clean things up, and if that's how others are doing it.


yeah, make sure your materials are in order.

Are you modifying the terrain material in code or are you just loading it from the .material script? (or both?)

I remember having to tweak with stuff for a while until I got everything unloading/loading properly. I even went through this same question: "Keep the splatMgr? Delete the splatMgr?"

What you're supposed to do:

Delete the terrainMgr and the splatMgr and recreate them for each terrain you load.

I've been through a lot of lines of code since I wrote this part of my app... post if you're still having problems and I'll look through my code tomorrow and see if I can remember any of the gotchas that I fell into (I remember there being at least one or two... though I think it was mostly due to me not fully comprehending how the resource managers worked at the time.)

MisterMayhem

30-01-2008 17:55:18

thanks for the tips. I sort of thought it might be that something is being held in the resources. I'll give your suggestions a try and I'll report on how it goes.

MisterMayhem

01-02-2008 23:25:41

A simple call to Resource::unload() for the terrain material after uloading the textures cleared it all up. I learned that the call to unload() does not really mess up using the same material again (at least when the material comes from a script).

Thanks for the help.