From ec21ff21cc6620ba60a947dcc7d7bf1ffcf12e36 Mon Sep 17 00:00:00 2001 From: Jacob Essex Date: Tue, 27 Mar 2012 13:58:12 +0100 Subject: [PATCH] Removed memory leak, allocated more on the stack --- apps/openmw/mwrender/terrain.cpp | 48 +++++++++++++------------------ apps/openmw/mwrender/terrain.hpp | 5 ++-- components/esm_store/reclists.hpp | 8 +++++- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp index 1c7db2d8b1..ac60e63238 100644 --- a/apps/openmw/mwrender/terrain.cpp +++ b/apps/openmw/mwrender/terrain.cpp @@ -16,33 +16,32 @@ namespace MWRender //---------------------------------------------------------------------------------------------- TerrainManager::TerrainManager(Ogre::SceneManager* mgr, const MWWorld::Environment& evn) : - mEnvironment(evn) + mEnvironment(evn), mTerrainGroup(TerrainGroup(mgr, Terrain::ALIGN_X_Z, mLandSize, mWorldSize)) { - mTerrainGlobals = OGRE_NEW TerrainGlobalOptions(); TerrainMaterialGeneratorPtr matGen; TerrainMaterialGeneratorB* matGenP = new TerrainMaterialGeneratorB(); matGen.bind(matGenP); - mTerrainGlobals->setDefaultMaterialGenerator(matGen); + mTerrainGlobals.setDefaultMaterialGenerator(matGen); TerrainMaterialGenerator::Profile* const activeProfile = - mTerrainGlobals->getDefaultMaterialGenerator() + mTerrainGlobals.getDefaultMaterialGenerator() ->getActiveProfile(); mActiveProfile = static_cast(activeProfile); //The pixel error should be as high as possible without it being noticed //as it governs how fast mesh quality decreases. - mTerrainGlobals->setMaxPixelError(8); + mTerrainGlobals.setMaxPixelError(8); - mTerrainGlobals->setLayerBlendMapSize(32); - mTerrainGlobals->setDefaultGlobalColourMapSize(65); + mTerrainGlobals.setLayerBlendMapSize(32); + mTerrainGlobals.setDefaultGlobalColourMapSize(65); //10 (default) didn't seem to be quite enough - mTerrainGlobals->setSkirtSize(128); + mTerrainGlobals.setSkirtSize(128); //due to the sudden flick between composite and non composite textures, //this seemed the distance where it wasn't too noticeable - mTerrainGlobals->setCompositeMapDistance(mWorldSize*2); + mTerrainGlobals.setCompositeMapDistance(mWorldSize*2); mActiveProfile->setLightmapEnabled(false); mActiveProfile->setLayerSpecularMappingEnabled(false); @@ -54,16 +53,11 @@ namespace MWRender //disabled mActiveProfile->setCompositeMapEnabled(false); - mTerrainGroup = OGRE_NEW TerrainGroup(mgr, - Terrain::ALIGN_X_Z, - mLandSize, - mWorldSize); - - mTerrainGroup->setOrigin(Vector3(mWorldSize/2, + mTerrainGroup.setOrigin(Vector3(mWorldSize/2, 0, -mWorldSize/2)); - Terrain::ImportData& importSettings = mTerrainGroup->getDefaultImportSettings(); + Terrain::ImportData& importSettings = mTerrainGroup.getDefaultImportSettings(); importSettings.inputBias = 0; importSettings.terrainSize = mLandSize; @@ -78,22 +72,20 @@ namespace MWRender TerrainManager::~TerrainManager() { - OGRE_DELETE mTerrainGroup; - OGRE_DELETE mTerrainGlobals; } //---------------------------------------------------------------------------------------------- void TerrainManager::setDiffuse(const ColourValue& diffuse) { - mTerrainGlobals->setCompositeMapDiffuse(diffuse); + mTerrainGlobals.setCompositeMapDiffuse(diffuse); } //---------------------------------------------------------------------------------------------- void TerrainManager::setAmbient(const ColourValue& ambient) { - mTerrainGlobals->setCompositeMapAmbient(ambient); + mTerrainGlobals.setCompositeMapAmbient(ambient); } //---------------------------------------------------------------------------------------------- @@ -117,7 +109,7 @@ namespace MWRender for ( int y = 0; y < 2; y++ ) { Terrain::ImportData terrainData = - mTerrainGroup->getDefaultImportSettings(); + mTerrainGroup.getDefaultImportSettings(); const int terrainX = cellX * 2 + x; const int terrainY = cellY * 2 + y; @@ -155,13 +147,13 @@ namespace MWRender x * numTextures, y * numTextures, numTextures, indexes); - if (mTerrainGroup->getTerrain(terrainX, terrainY) == NULL) + if (mTerrainGroup.getTerrain(terrainX, terrainY) == NULL) { - mTerrainGroup->defineTerrain(terrainX, terrainY, &terrainData); + mTerrainGroup.defineTerrain(terrainX, terrainY, &terrainData); - mTerrainGroup->loadTerrain(terrainX, terrainY, true); + mTerrainGroup.loadTerrain(terrainX, terrainY, true); - Terrain* terrain = mTerrainGroup->getTerrain(terrainX, terrainY); + Terrain* terrain = mTerrainGroup.getTerrain(terrainX, terrainY); initTerrainBlendMaps(terrain, cellX, cellY, x * numTextures, y * numTextures, @@ -193,7 +185,7 @@ namespace MWRender } } - mTerrainGroup->freeTemporaryResources(); + mTerrainGroup.freeTemporaryResources(); } //---------------------------------------------------------------------------------------------- @@ -204,8 +196,8 @@ namespace MWRender { for ( int y = 0; y < 2; y++ ) { - mTerrainGroup->unloadTerrain(store->cell->getGridX() * 2 + x, - store->cell->getGridY() * 2 + y); + mTerrainGroup.unloadTerrain(store->cell->getGridX() * 2 + x, + store->cell->getGridY() * 2 + y); } } } diff --git a/apps/openmw/mwrender/terrain.hpp b/apps/openmw/mwrender/terrain.hpp index 16c93d6f49..29a4ba36b3 100644 --- a/apps/openmw/mwrender/terrain.hpp +++ b/apps/openmw/mwrender/terrain.hpp @@ -2,6 +2,7 @@ #define _GAME_RENDER_TERRAIN_H #include +#include #include "terrainmaterial.hpp" #include "../mwworld/ptr.hpp" @@ -32,8 +33,8 @@ namespace MWRender{ void cellAdded(MWWorld::Ptr::CellStore* store); void cellRemoved(MWWorld::Ptr::CellStore* store); private: - Ogre::TerrainGlobalOptions* mTerrainGlobals; - Ogre::TerrainGroup* mTerrainGroup; + Ogre::TerrainGlobalOptions mTerrainGlobals; + Ogre::TerrainGroup mTerrainGroup; const MWWorld::Environment& mEnvironment; diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index a991996be5..16d37bec71 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -239,7 +239,13 @@ namespace ESMS */ struct LandList : RecList { - virtual ~LandList() {} + virtual ~LandList() + { + for ( LandMap::iterator itr = lands.begin(); itr != lands.end(); ++itr ) + { + delete itr->second; + } + } // Map containing all landscapes typedef std::pair LandCoord;