From 035fb6ad1cdb8ca126ac8dd5a930b954f650061c Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 13:53:26 +0200 Subject: CGE2: Hopefully fix a memory leak problem regarding Hero::_dim; --- engines/cge2/hero.cpp | 28 +++++++++------------------- engines/cge2/hero.h | 2 +- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 6281e4dd5e..677811885e 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -33,11 +33,7 @@ namespace CGE2 { Hero::Hero(CGE2Engine *vm) : Sprite(vm), _contact(nullptr), _dir(kNoDir), - _curDim(0), _tracePtr(-1), _ignoreMap(false) { - - for (int i = 0; i < kDimMax; i++) { - _dim[i] = nullptr; - } + _curDim(0), _tracePtr(-1), _ignoreMap(false), _isDimLoaded(false) { } Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! @@ -62,10 +58,14 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo Seq *seq; int section = kIdPhase; - for (int i = 0; i < kDimMax; i++) { - _dim[i] = new Bitmap[_shpCnt]; - for (int j = 0; j < _shpCnt; j++) - _dim[i][j].setVM(_vm); + if (!_isDimLoaded) { + for (int i = 0; i < kDimMax; i++) { + _dim[i] = new Bitmap[_shpCnt]; + for (int j = 0; j < _shpCnt; j++) + _dim[i][j].setVM(_vm); + } + + _isDimLoaded = true; } if (_seqCnt) { @@ -200,16 +200,6 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo return this; } -Sprite *Hero::contract() { - /* TODO: Recheck this later! - for (int i = 0; i < kDimMax; i++) { - if (_dim[i] != nullptr) - delete[] _dim[i]; - } - */ - return this; -} - void Hero::setCurrent() { FXP m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); FXP tmp = m * _siz.y; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index c277b4a780..f45a65211b 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -62,6 +62,7 @@ struct HeroTab { }; class Hero : public Sprite { + bool _isDimLoaded; int _hig[kDimMax]; Sprite *_contact; public: @@ -77,7 +78,6 @@ public: Hero(CGE2Engine *vm); void tick(); Sprite *expand(); - Sprite *contract(); Sprite *setContact(); int stepSize() { return _ext->_seq[7]._dx; } int distance(V3D pos); -- cgit v1.2.3