From ae989040e58a6b8c688d545a0b6278868e7ce9b7 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 1 Apr 2012 21:29:49 +0200 Subject: [PATCH] Issue #225: Fix for memleak when loading terrain. --- apps/openmw/mwrender/terrain.cpp | 11 +++++++++-- components/esm/loadland.cpp | 18 ++++++++++++++++++ components/esm/loadland.hpp | 3 +++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp index 8877215653..0b8f933a27 100644 --- a/apps/openmw/mwrender/terrain.cpp +++ b/apps/openmw/mwrender/terrain.cpp @@ -98,7 +98,10 @@ namespace MWRender ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY); if ( land != NULL ) { - land->loadData(); + if (!land->dataLoaded) + { + land->loadData(); + } } //split the cell terrain into four segments @@ -420,7 +423,11 @@ namespace MWRender ESM::Land* land = mEnvironment.mWorld->getStore().lands.search(cellX, cellY); if ( land != NULL ) { - land->loadData(); + if (!land->dataLoaded) + { + land->loadData(); + } + return land->landData ->textures[y * ESM::Land::LAND_TEXTURE_SIZE + x]; } diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index cd2cf1d917..96afdf8316 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -2,6 +2,24 @@ namespace ESM { + +Land::Land() + : flags(0) + , X(0) + , Y(0) + , mEsm(NULL) + , hasData(false) + , dataLoaded(false) + , landData(NULL) +{ +} + +Land::~Land() +{ + delete landData; +} + + void Land::load(ESMReader &esm) { mEsm = &esm; diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 5ccd966d92..64baecd349 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -11,6 +11,9 @@ namespace ESM struct Land { + Land(); + ~Land(); + int flags; // Only first four bits seem to be used, don't know what // they mean. int X, Y; // Map coordinates.