aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Turner2010-11-08 03:14:32 +0000
committerDavid Turner2010-11-08 03:14:32 +0000
commit5d30eeea95be5a295ac17b0736779297606a08a8 (patch)
tree1f590114a49efbcd912e6d5594d93889626fc57f
parent05eb352e5c4c9dd359640954100038d195713bce (diff)
downloadscummvm-rg350-5d30eeea95be5a295ac17b0736779297606a08a8.tar.gz
scummvm-rg350-5d30eeea95be5a295ac17b0736779297606a08a8.tar.bz2
scummvm-rg350-5d30eeea95be5a295ac17b0736779297606a08a8.zip
TOON: Further corrections to close memory leaks.
These corrections close a number of leaks in the Toon engine reported by running Valgrind with --leak-check=full option, but a significant number still remain. svn-id: r54136
-rw-r--r--engines/toon/audio.cpp10
-rw-r--r--engines/toon/character.cpp8
-rw-r--r--engines/toon/path.cpp20
-rw-r--r--engines/toon/path.h13
-rw-r--r--engines/toon/script.cpp3
-rw-r--r--engines/toon/script.h2
-rw-r--r--engines/toon/script_func.cpp5
-rw-r--r--engines/toon/toon.cpp17
8 files changed, 56 insertions, 22 deletions
diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp
index e3c6de8c71..386d00ef77 100644
--- a/engines/toon/audio.cpp
+++ b/engines/toon/audio.cpp
@@ -482,16 +482,13 @@ void AudioStreamInstance::setVolume(int32 volume) {
}
AudioStreamPackage::AudioStreamPackage(ToonEngine *vm) : _vm(vm) {
- _indexBuffer = 0;
- _file = 0;
+ _indexBuffer = NULL;
+ _file = NULL;
}
AudioStreamPackage::~AudioStreamPackage() {
delete[] _indexBuffer;
- if (_file) {
- delete _file;
- _file = 0;
- }
+ delete _file;
}
bool AudioStreamPackage::loadAudioPackage(Common::String indexFile, Common::String streamFile) {
@@ -503,7 +500,6 @@ bool AudioStreamPackage::loadAudioPackage(Common::String indexFile, Common::Stri
return false;
delete[] _indexBuffer;
-
_indexBuffer = new uint32[size / 4];
memcpy(_indexBuffer, fileData, size);
diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp
index e4cb48050e..65c4135433 100644
--- a/engines/toon/character.cpp
+++ b/engines/toon/character.cpp
@@ -32,8 +32,8 @@ namespace Toon {
Character::Character(ToonEngine *vm) : _vm(vm) {
_animationInstance = 0;
- _shadowAnimationInstance = 0;
- _shadowAnim = 0;
+ _shadowAnimationInstance = NULL;
+ _shadowAnim = NULL;
_x = 0;
_y = 0;
_z = 0;
@@ -64,6 +64,8 @@ Character::Character(ToonEngine *vm) : _vm(vm) {
}
Character::~Character(void) {
+ delete _shadowAnimationInstance;
+ delete _shadowAnim;
}
void Character::init() {
@@ -918,10 +920,12 @@ const SpecialCharacterAnimation *Character::getSpecialAnimation(int32 characterI
bool Character::loadShadowAnimation(Common::String animName) {
debugC(1, kDebugCharacter, "loadShadowAnimation(%s)", animName.c_str());
+ delete _shadowAnim;
_shadowAnim = new Animation(_vm);
if (!_shadowAnim->loadAnimation(animName))
return false;
+ delete _shadowAnimationInstance;
_shadowAnimationInstance = _vm->getAnimationManager()->createNewInstance(kAnimationCharacter);
_vm->getAnimationManager()->addInstance(_shadowAnimationInstance);
_shadowAnimationInstance->setAnimation(_shadowAnim);
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index f804f5aae5..18b7956245 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -27,9 +27,20 @@
namespace Toon {
+PathFindingHeap::PathFindingHeap() {
+ _count = 0;
+ _alloc = 0;
+ _data = NULL;
+}
+
+PathFindingHeap::~PathFindingHeap() {
+ delete[] _data;
+}
+
int32 PathFindingHeap::init(int32 size) {
debugC(1, kDebugPath, "init(%d)", size);
+ delete[] _data;
_data = new HeapDataGrid[size * 2];
memset(_data, 0, sizeof(HeapDataGrid) * size * 2);
_count = 0;
@@ -38,8 +49,8 @@ int32 PathFindingHeap::init(int32 size) {
}
int32 PathFindingHeap::unload() {
- if (_data)
- delete[] _data;
+ delete[] _data;
+ _data = NULL;
return 0;
}
@@ -131,10 +142,9 @@ PathFinding::PathFinding(ToonEngine *vm) : _vm(vm) {
}
PathFinding::~PathFinding(void) {
- if (_heap) {
+ if (_heap)
_heap->unload();
- delete _heap;
- }
+ delete _heap;
delete[] _gridTemp;
}
diff --git a/engines/toon/path.h b/engines/toon/path.h
index d8ef2eac02..04a076525e 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -37,24 +37,27 @@ struct HeapDataGrid {
};
class PathFindingHeap {
-
-private:
- HeapDataGrid *_data;
public:
+ PathFindingHeap();
+ ~PathFindingHeap();
+
int32 _alloc;
int32 _count;
+
int32 push(int32 x, int32 y, int32 weight);
int32 pop(int32 *x, int32 *y, int32 *weight);
int32 init(int32 size);
int32 clear();
int32 unload();
-};
+private:
+ HeapDataGrid *_data;
+};
class PathFinding {
public:
PathFinding(ToonEngine *vm);
- ~PathFinding(void);
+ ~PathFinding();
int32 findPath(int32 x, int32 y, int32 destX, int32 destY);
int32 findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX = -1, int origY = -1);
diff --git a/engines/toon/script.cpp b/engines/toon/script.cpp
index 31d9f94f36..5e56432012 100644
--- a/engines/toon/script.cpp
+++ b/engines/toon/script.cpp
@@ -66,6 +66,9 @@ EMCInterpreter::EMCInterpreter(ToonEngine *vm) : _vm(vm), _scriptData(0), _filen
#undef OPCODE
}
+EMCInterpreter::~EMCInterpreter() {
+}
+
bool EMCInterpreter::callback(Common::IFFChunk &chunk) {
switch (chunk._type) {
case MKID_BE('TEXT'):
diff --git a/engines/toon/script.h b/engines/toon/script.h
index d7f45096c2..6c46238238 100644
--- a/engines/toon/script.h
+++ b/engines/toon/script.h
@@ -98,6 +98,7 @@ public:
class EMCInterpreter {
public:
EMCInterpreter(ToonEngine *vm);
+ ~EMCInterpreter();
bool load(const char *filename, EMCData *data, const Common::Array<const OpcodeV2 *> *opcodes);
void unload(EMCData *data);
@@ -147,6 +148,7 @@ private:
void op_eval(EMCState *);
void op_setRetAndJmp(EMCState *);
};
+
} // End of namespace Toon
#endif
diff --git a/engines/toon/script_func.cpp b/engines/toon/script_func.cpp
index c62211a1ae..4c30b1530a 100644
--- a/engines/toon/script_func.cpp
+++ b/engines/toon/script_func.cpp
@@ -223,7 +223,10 @@ ScriptFunc::ScriptFunc(ToonEngine *vm) {
}
ScriptFunc::~ScriptFunc(void) {
-
+ while(!_opcodes.empty()) {
+ //delete _opcodes.end();
+ _opcodes.pop_back();
+ }
}
char *GetText(int32 i, EMCState *state) {
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 78947d5a7e..4221c5da8b 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -131,7 +131,6 @@ void ToonEngine::init() {
memset(_sceneAnimations, 0, sizeof(_sceneAnimations));
memset(_sceneAnimationScripts, 0, sizeof(_sceneAnimationScripts));
-
_gameState->_currentChapter = 1;
initChapter();
loadCursor();
@@ -755,10 +754,16 @@ ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription)
DebugMan.addDebugChannel(kDebugTools, "Tools", "Tools debug level");
DebugMan.addDebugChannel(kDebugText, "Text", "Text debug level");
- _hotspots = NULL;
+ _moviePlayer = NULL;
+ _mainSurface = NULL;
_fontRenderer = NULL;
_fontToon = NULL;
_fontEZ = NULL;
+ _hotspots = NULL;
+ _genericTexts = NULL;
+ _roomTexts = NULL;
+ _script_func = NULL;
+ _script = NULL;
_console = new ToonConsole(this);
switch (_language) {
@@ -787,10 +792,17 @@ ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription)
}
ToonEngine::~ToonEngine() {
+ delete _moviePlayer;
+ delete _mainSurface;
+
delete _fontRenderer;
delete _fontToon;
delete _fontEZ;
delete _hotspots;
+ delete _genericTexts;
+ delete _roomTexts;
+ delete _script_func;
+ delete _script;
DebugMan.clearAllDebugChannels();
delete _console;
@@ -1171,6 +1183,7 @@ void ToonEngine::initChapter() {
memset(&data, 0, sizeof(data));
memset(&status, 0, sizeof(status));
+ delete _script;
_script = new EMCInterpreter(this);
_script->load("_START01.EMC", &data, &_script_func->_opcodes);