Code: Select all
void WorldManager::load(Ogre::String load)
{
unload(); // Unload the previous world..
Ogre::SceneManager* sceneMgr = Application::getSingleton().getSceneManager();
if(load == "") // Create new..
{
mTerrain = OGRE_NEW Ogre::Terrain(sceneMgr);
Ogre::Terrain::ImportData imp;
//imp.inputImage = &img; // No image = flat terrain..
imp.terrainSize = 513;
imp.worldSize = 12000.0f;
imp.inputScale = 600;
imp.minBatchSize = 33;
imp.maxBatchSize = 65;
// textures
imp.layerList.resize(3);
imp.layerList[0].worldSize = 100;
imp.layerList[0].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
imp.layerList[0].textureNames.push_back("dirt_grayrocky_normalheight.dds");
imp.layerList[1].worldSize = 30;
imp.layerList[1].textureNames.push_back("grass_green-01_diffusespecular.dds");
imp.layerList[1].textureNames.push_back("grass_green-01_normalheight.dds");
imp.layerList[2].worldSize = 200;
imp.layerList[2].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
imp.layerList[2].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");
mTerrain->prepare(imp);
mTerrain->load();
Ogre::TerrainLayerBlendMap* blendMap0 = mTerrain->getLayerBlendMap(1);
Ogre::TerrainLayerBlendMap* blendMap1 = mTerrain->getLayerBlendMap(2);
Ogre::Real minHeight0 = 70;
Ogre::Real fadeDist0 = 40;
Ogre::Real minHeight1 = 70;
Ogre::Real fadeDist1 = 15;
float* pBlend1 = blendMap1->getBlendPointer();
for (Ogre::uint16 y = 0; y < mTerrain->getLayerBlendMapSize(); ++y)
{
for (Ogre::uint16 x = 0; x < mTerrain->getLayerBlendMapSize(); ++x)
{
Ogre::Real tx, ty;
blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty);
Ogre::Real height = mTerrain->getHeightAtTerrainPosition(tx, ty);
Ogre::Real val = (height - minHeight0) / fadeDist0;
val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
val = (height - minHeight1) / fadeDist1;
val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
*pBlend1++ = val;
}
}
blendMap0->dirty();
blendMap1->dirty();
blendMap0->update();
blendMap1->update();
mTerrain->freeTemporaryResources();
}
Now on WorldManager destruction (as the application is being shut down - just before root is deleted)
Code: Select all
OGRE_DELETE mTerrainGlobalOptions;
unload();
Code: Select all
void WorldManager::unload(void)
{
if (mTerrain)
{
std::cout << "About to unload.. " << std::endl;
mTerrain->unload();
std::cout << "About to unprepare.. " << std::endl;
mTerrain->unprepare();
std::cout << "About to delete.. " << std::endl;
OGRE_DELETE mTerrain;
std::cout << "Done" << std::endl;
}
}
I'm pretty sure, although not absolutely certain, that this is caused by the "waitForDerivedProcesses()" function in the Terrain object.
My question is.. Why does this happen for a single terrain instance, when a terrain group is destructed almost immedially?
Thanks in advance.
- Mikkel
EDIT: Say I remove the "OGRE_DELETE mTerrain" - the application is going to freeze after having shut down a couple of worker threads..