From fc2bb50600e393cdb3d1e868b9274a43d05bca21 Mon Sep 17 00:00:00 2001 From: Robert Špalek Date: Sun, 27 Sep 2009 18:11:06 +0000 Subject: Remove memory leak in animation manager. Get rid of 1 non-const reference parameter. svn-id: r44413 --- engines/draci/animation.cpp | 12 ++++++------ engines/draci/animation.h | 9 ++++++++- engines/draci/script.cpp | 18 +++++++++--------- engines/draci/script.h | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) (limited to 'engines/draci') diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp index f4333c01de..746d577d3a 100644 --- a/engines/draci/animation.cpp +++ b/engines/draci/animation.cpp @@ -501,12 +501,12 @@ void AnimationManager::deleteAnimation(int id) { // Iterate for the first time to delete the animation for (it = _animations.begin(); it != _animations.end(); ++it) { if ((*it)->getID() == id) { - (*it)->deleteFrames(); - _animations.erase(it); - // Remember index of the deleted animation index = (*it)->getIndex(); + delete *it; + _animations.erase(it); + debugC(3, kDraciAnimationDebugLevel, "Deleting animation %d...", id); break; @@ -532,7 +532,7 @@ void AnimationManager::deleteOverlays() { for (it = _animations.begin(); it != _animations.end(); ++it) { if ((*it)->getID() == kOverlayImage) { - (*it)->deleteFrames(); + delete *it; _animations.erase(it); } } @@ -545,7 +545,7 @@ void AnimationManager::deleteAll() { Common::List::iterator it; for (it = _animations.begin(); it != _animations.end(); ++it) { - (*it)->deleteFrames(); + delete *it; } _animations.clear(); @@ -566,7 +566,7 @@ void AnimationManager::deleteAfterIndex(int index) { debugC(3, kDraciAnimationDebugLevel, "Deleting animation %d...", (*it)->getID()); - (*it)->deleteFrames(); + delete *it; _animations.erase(it); } } diff --git a/engines/draci/animation.h b/engines/draci/animation.h index d71da984cd..2358775d8d 100644 --- a/engines/draci/animation.h +++ b/engines/draci/animation.h @@ -79,7 +79,6 @@ public: void setCurrentFrame(uint frame); uint currentFrameNum() const; uint getFrameCount() const; - void deleteFrames(); bool isPlaying() const; void setPlaying(bool playing); @@ -114,6 +113,7 @@ public: private: uint nextFrameNum() const; + void deleteFrames(); /** Internal animation ID * (as specified in the data files and the bytecode) @@ -138,6 +138,9 @@ private: bool _playing; bool _looping; bool _paused; + + /** Array of frames of the animation. The animation object owns these pointers. + */ Common::Array _frames; AnimationCallback _callback; @@ -180,6 +183,10 @@ private: void insertAnimation(Animation *anim); DraciEngine *_vm; + + /** List of animation objects, maintained sorted by decreasing Z-coordinates. + * The animation manager owns the pointers. + */ Common::List _animations; /** The index of the most recently added animation. diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index 7cac75b757..3622f2d028 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -799,7 +799,7 @@ void Script::endCurrentProgram() { * @param reader Stream reader set to the beginning of the expression */ -int Script::handleMathExpression(Common::MemoryReadStream &reader) const { +int Script::handleMathExpression(Common::MemoryReadStream *reader) const { Common::Stack stk; mathExpressionObject obj; GPL2Operator oper; @@ -808,7 +808,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const { debugC(4, kDraciBytecodeDebugLevel, "\t"); // Read in initial math object - obj = (mathExpressionObject)reader.readSint16LE(); + obj = (mathExpressionObject)reader->readSint16LE(); int value; int arg1, arg2, res; @@ -827,13 +827,13 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const { // If the object type is not known, assume that it's a number default: case kMathNumber: - value = reader.readSint16LE(); + value = reader->readSint16LE(); stk.push(value); debugC(4, kDraciBytecodeDebugLevel, "\t\tnumber: %d", value); break; case kMathOperator: - value = reader.readSint16LE(); + value = reader->readSint16LE(); arg2 = stk.pop(); arg1 = stk.pop(); @@ -851,7 +851,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const { break; case kMathVariable: - value = reader.readSint16LE() - 1; + value = reader->readSint16LE() - 1; stk.push(_vm->_game->getVariable(value)); @@ -860,7 +860,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const { break; case kMathFunctionCall: - value = reader.readSint16LE(); + value = reader->readSint16LE(); // Fetch function func = _functionList[value-1]; @@ -890,7 +890,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const { break; } - obj = (mathExpressionObject) reader.readSint16LE(); + obj = (mathExpressionObject) reader->readSint16LE(); } return stk.pop(); @@ -923,7 +923,7 @@ bool Script::testExpression(const GPL2Program &program, uint16 offset) const { debugC(4, kDraciBytecodeDebugLevel, "Evaluating (standalone) GPL expression at offset %d:", offset); - return (bool)handleMathExpression(reader); + return (bool)handleMathExpression(&reader); } /** @@ -1053,7 +1053,7 @@ int Script::run(const GPL2Program &program, uint16 offset) { if (cmd->_paramTypes[i] == 4) { debugC(3, kDraciBytecodeDebugLevel, "Evaluating (in-script) GPL expression at offset %d: ", offset); - params.push(handleMathExpression(reader)); + params.push(handleMathExpression(&reader)); } else { tmp = reader.readSint16LE(); diff --git a/engines/draci/script.h b/engines/draci/script.h index 4e94281b50..21a16c92fb 100644 --- a/engines/draci/script.h +++ b/engines/draci/script.h @@ -167,7 +167,7 @@ private: void setupCommandList(); const GPL2Command *findCommand(byte num, byte subnum) const; - int handleMathExpression(Common::MemoryReadStream &reader) const; + int handleMathExpression(Common::MemoryReadStream *reader) const; DraciEngine *_vm; }; -- cgit v1.2.3