Remove memory leak in animation manager. Get rid of 1 non-const reference parameter.

svn-id: r44413
This commit is contained in:
Robert Špalek 2009-09-27 18:11:06 +00:00
parent 8b6b3358c8
commit fc2bb50600
4 changed files with 24 additions and 17 deletions

View file

@ -501,12 +501,12 @@ void AnimationManager::deleteAnimation(int id) {
// Iterate for the first time to delete the animation // Iterate for the first time to delete the animation
for (it = _animations.begin(); it != _animations.end(); ++it) { for (it = _animations.begin(); it != _animations.end(); ++it) {
if ((*it)->getID() == id) { if ((*it)->getID() == id) {
(*it)->deleteFrames();
_animations.erase(it);
// Remember index of the deleted animation // Remember index of the deleted animation
index = (*it)->getIndex(); index = (*it)->getIndex();
delete *it;
_animations.erase(it);
debugC(3, kDraciAnimationDebugLevel, "Deleting animation %d...", id); debugC(3, kDraciAnimationDebugLevel, "Deleting animation %d...", id);
break; break;
@ -532,7 +532,7 @@ void AnimationManager::deleteOverlays() {
for (it = _animations.begin(); it != _animations.end(); ++it) { for (it = _animations.begin(); it != _animations.end(); ++it) {
if ((*it)->getID() == kOverlayImage) { if ((*it)->getID() == kOverlayImage) {
(*it)->deleteFrames(); delete *it;
_animations.erase(it); _animations.erase(it);
} }
} }
@ -545,7 +545,7 @@ void AnimationManager::deleteAll() {
Common::List<Animation *>::iterator it; Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) { for (it = _animations.begin(); it != _animations.end(); ++it) {
(*it)->deleteFrames(); delete *it;
} }
_animations.clear(); _animations.clear();
@ -566,7 +566,7 @@ void AnimationManager::deleteAfterIndex(int index) {
debugC(3, kDraciAnimationDebugLevel, "Deleting animation %d...", (*it)->getID()); debugC(3, kDraciAnimationDebugLevel, "Deleting animation %d...", (*it)->getID());
(*it)->deleteFrames(); delete *it;
_animations.erase(it); _animations.erase(it);
} }
} }

View file

@ -79,7 +79,6 @@ public:
void setCurrentFrame(uint frame); void setCurrentFrame(uint frame);
uint currentFrameNum() const; uint currentFrameNum() const;
uint getFrameCount() const; uint getFrameCount() const;
void deleteFrames();
bool isPlaying() const; bool isPlaying() const;
void setPlaying(bool playing); void setPlaying(bool playing);
@ -114,6 +113,7 @@ public:
private: private:
uint nextFrameNum() const; uint nextFrameNum() const;
void deleteFrames();
/** Internal animation ID /** Internal animation ID
* (as specified in the data files and the bytecode) * (as specified in the data files and the bytecode)
@ -138,6 +138,9 @@ private:
bool _playing; bool _playing;
bool _looping; bool _looping;
bool _paused; bool _paused;
/** Array of frames of the animation. The animation object owns these pointers.
*/
Common::Array<Drawable*> _frames; Common::Array<Drawable*> _frames;
AnimationCallback _callback; AnimationCallback _callback;
@ -180,6 +183,10 @@ private:
void insertAnimation(Animation *anim); void insertAnimation(Animation *anim);
DraciEngine *_vm; DraciEngine *_vm;
/** List of animation objects, maintained sorted by decreasing Z-coordinates.
* The animation manager owns the pointers.
*/
Common::List<Animation *> _animations; Common::List<Animation *> _animations;
/** The index of the most recently added animation. /** The index of the most recently added animation.

View file

@ -799,7 +799,7 @@ void Script::endCurrentProgram() {
* @param reader Stream reader set to the beginning of the expression * @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<int> stk; Common::Stack<int> stk;
mathExpressionObject obj; mathExpressionObject obj;
GPL2Operator oper; GPL2Operator oper;
@ -808,7 +808,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const {
debugC(4, kDraciBytecodeDebugLevel, "\t<MATHEXPR>"); debugC(4, kDraciBytecodeDebugLevel, "\t<MATHEXPR>");
// Read in initial math object // Read in initial math object
obj = (mathExpressionObject)reader.readSint16LE(); obj = (mathExpressionObject)reader->readSint16LE();
int value; int value;
int arg1, arg2, res; 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 // If the object type is not known, assume that it's a number
default: default:
case kMathNumber: case kMathNumber:
value = reader.readSint16LE(); value = reader->readSint16LE();
stk.push(value); stk.push(value);
debugC(4, kDraciBytecodeDebugLevel, "\t\tnumber: %d", value); debugC(4, kDraciBytecodeDebugLevel, "\t\tnumber: %d", value);
break; break;
case kMathOperator: case kMathOperator:
value = reader.readSint16LE(); value = reader->readSint16LE();
arg2 = stk.pop(); arg2 = stk.pop();
arg1 = stk.pop(); arg1 = stk.pop();
@ -851,7 +851,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const {
break; break;
case kMathVariable: case kMathVariable:
value = reader.readSint16LE() - 1; value = reader->readSint16LE() - 1;
stk.push(_vm->_game->getVariable(value)); stk.push(_vm->_game->getVariable(value));
@ -860,7 +860,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const {
break; break;
case kMathFunctionCall: case kMathFunctionCall:
value = reader.readSint16LE(); value = reader->readSint16LE();
// Fetch function // Fetch function
func = _functionList[value-1]; func = _functionList[value-1];
@ -890,7 +890,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const {
break; break;
} }
obj = (mathExpressionObject) reader.readSint16LE(); obj = (mathExpressionObject) reader->readSint16LE();
} }
return stk.pop(); return stk.pop();
@ -923,7 +923,7 @@ bool Script::testExpression(const GPL2Program &program, uint16 offset) const {
debugC(4, kDraciBytecodeDebugLevel, debugC(4, kDraciBytecodeDebugLevel,
"Evaluating (standalone) GPL expression at offset %d:", offset); "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) { if (cmd->_paramTypes[i] == 4) {
debugC(3, kDraciBytecodeDebugLevel, debugC(3, kDraciBytecodeDebugLevel,
"Evaluating (in-script) GPL expression at offset %d: ", offset); "Evaluating (in-script) GPL expression at offset %d: ", offset);
params.push(handleMathExpression(reader)); params.push(handleMathExpression(&reader));
} }
else { else {
tmp = reader.readSint16LE(); tmp = reader.readSint16LE();

View file

@ -167,7 +167,7 @@ private:
void setupCommandList(); void setupCommandList();
const GPL2Command *findCommand(byte num, byte subnum) const; const GPL2Command *findCommand(byte num, byte subnum) const;
int handleMathExpression(Common::MemoryReadStream &reader) const; int handleMathExpression(Common::MemoryReadStream *reader) const;
DraciEngine *_vm; DraciEngine *_vm;
}; };