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
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<Animation *>::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);
}
}

View file

@ -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<Drawable*> _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<Animation *> _animations;
/** 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
*/
int Script::handleMathExpression(Common::MemoryReadStream &reader) const {
int Script::handleMathExpression(Common::MemoryReadStream *reader) const {
Common::Stack<int> stk;
mathExpressionObject obj;
GPL2Operator oper;
@ -808,7 +808,7 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) const {
debugC(4, kDraciBytecodeDebugLevel, "\t<MATHEXPR>");
// 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();

View file

@ -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;
};