HDB: Add _animTiles to fix memory leaks

This commit is contained in:
Nipun Garg 2019-07-18 20:11:26 +05:30 committed by Eugene Sandulenko
parent a8d277be18
commit ecefec2f77
5 changed files with 33 additions and 11 deletions

View File

@ -681,6 +681,7 @@ int AI::checkForTouchplate(int x, int y) {
void AI::removeEntity(AIEntity *e) { void AI::removeEntity(AIEntity *e) {
for (uint i = 0; i < _ents->size(); i++) for (uint i = 0; i < _ents->size(); i++)
if (_ents->operator[](i) == e) { if (_ents->operator[](i) == e) {
delete _ents->operator[](i);
_ents->remove_at(i); _ents->remove_at(i);
return; return;
} }

View File

@ -941,6 +941,15 @@ AI::~AI() {
// Free Player Graphics // Free Player Graphics
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
delete _slugAttackGfx[i]; delete _slugAttackGfx[i];
_slugAttackGfx[i] = NULL;
}
if (_weaponSelGfx) {
delete _weaponSelGfx;
_weaponSelGfx = NULL;
}
if (_weaponGfx) {
delete _weaponGfx;
_weaponGfx = NULL;
} }
memset(_clubDownGfx, 0, sizeof(_clubDownGfx)); memset(_clubDownGfx, 0, sizeof(_clubDownGfx));
@ -979,6 +988,9 @@ AI::~AI() {
for (uint i = 0; i < _animTargets.size(); i++) { for (uint i = 0; i < _animTargets.size(); i++) {
delete _animTargets[i]; delete _animTargets[i];
} }
// Free Animating Tiles
freeAnimInfo();
} }
bool AI::init() { bool AI::init() {
@ -1768,13 +1780,13 @@ void AI::loadSaveFile(Common::InSaveFile *in) {
void AI::initAnimInfo() { void AI::initAnimInfo() {
if (g_hdb->_map->checkOneTileExistInRange(_useSwitchOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_useSwitchOff, 2))
g_hdb->_gfx->getTile(_useSwitchOn); _animTiles.push_back(g_hdb->_gfx->getTile(_useSwitchOn));
if (g_hdb->_map->checkOneTileExistInRange(_useSwitch2Off, 2)) if (g_hdb->_map->checkOneTileExistInRange(_useSwitch2Off, 2))
g_hdb->_gfx->getTile(_useSwitch2On); _animTiles.push_back(g_hdb->_gfx->getTile(_useSwitch2On));
if (g_hdb->_map->checkOneTileExistInRange(_useHolderEmpty, 2)) if (g_hdb->_map->checkOneTileExistInRange(_useHolderEmpty, 2))
g_hdb->_gfx->getTile(_useHolderFull); _animTiles.push_back(g_hdb->_gfx->getTile(_useHolderFull));
if (g_hdb->_map->checkOneTileExistInRange(_useHandswitchOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_useHandswitchOff, 2))
g_hdb->_gfx->getTile(_useHandswitchOn); _animTiles.push_back(g_hdb->_gfx->getTile(_useHandswitchOn));
if (g_hdb->_map->checkOneTileExistInRange(_targetDoorN, 4)) if (g_hdb->_map->checkOneTileExistInRange(_targetDoorN, 4))
g_hdb->_gfx->cacheTileSequence(_targetDoorN, 4); g_hdb->_gfx->cacheTileSequence(_targetDoorN, 4);
@ -1848,17 +1860,22 @@ void AI::initAnimInfo() {
g_hdb->_gfx->cacheTileSequence(_blockpole, 4); g_hdb->_gfx->cacheTileSequence(_blockpole, 4);
if (g_hdb->_map->checkOneTileExistInRange(_kcHolderWhiteOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_kcHolderWhiteOff, 2))
g_hdb->_gfx->getTile(_kcHolderWhiteOn); _animTiles.push_back(g_hdb->_gfx->getTile(_kcHolderWhiteOn));
if (g_hdb->_map->checkOneTileExistInRange(_kcHolderBlueOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_kcHolderBlueOff, 2))
g_hdb->_gfx->getTile(_kcHolderBlueOn); _animTiles.push_back(g_hdb->_gfx->getTile(_kcHolderBlueOn));
if (g_hdb->_map->checkOneTileExistInRange(_kcHolderRedOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_kcHolderRedOff, 2))
g_hdb->_gfx->getTile(_kcHolderRedOn); _animTiles.push_back(g_hdb->_gfx->getTile(_kcHolderRedOn));
if (g_hdb->_map->checkOneTileExistInRange(_kcHolderGreenOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_kcHolderGreenOff, 2))
g_hdb->_gfx->getTile(_kcHolderGreenOn); _animTiles.push_back(g_hdb->_gfx->getTile(_kcHolderGreenOn));
if (g_hdb->_map->checkOneTileExistInRange(_kcHolderPurpleOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_kcHolderPurpleOff, 2))
g_hdb->_gfx->getTile(_kcHolderPurpleOn); _animTiles.push_back(g_hdb->_gfx->getTile(_kcHolderPurpleOn));
if (g_hdb->_map->checkOneTileExistInRange(_kcHolderBlackOff, 2)) if (g_hdb->_map->checkOneTileExistInRange(_kcHolderBlackOff, 2))
g_hdb->_gfx->getTile(_kcHolderBlackOn); _animTiles.push_back(g_hdb->_gfx->getTile(_kcHolderBlackOn));
}
void AI::freeAnimInfo() {
for (uint i = 0; i < _animTiles.size(); i++)
delete _animTiles[i];
} }
const char *AITypeStr[] = { const char *AITypeStr[] = {

View File

@ -821,6 +821,7 @@ public:
void save(Common::OutSaveFile *out); void save(Common::OutSaveFile *out);
void loadSaveFile(Common::InSaveFile *in); void loadSaveFile(Common::InSaveFile *in);
void initAnimInfo(); void initAnimInfo();
void freeAnimInfo();
// Entity Functions // Entity Functions
AIEntity *spawn(AIType type, AIDir dir, int x, int y, const char *funcInit, const char *funcAction, const char *funcUse, AIDir dir2, int level, int value1, int value2, int callInit); AIEntity *spawn(AIType type, AIDir dir, int x, int y, const char *funcInit, const char *funcAction, const char *funcUse, AIDir dir2, int level, int value1, int value2, int callInit);
@ -1327,6 +1328,8 @@ public:
Tile *_gfxLaserbeamLRLeft[4]; Tile *_gfxLaserbeamLRLeft[4];
Tile *_gfxLaserbeamLRRight[4]; Tile *_gfxLaserbeamLRRight[4];
Common::Array<Tile *> _animTiles;
private: private:
// Action Functions // Action Functions

View File

@ -459,7 +459,7 @@ void Gfx::emptyGfxCaches() {
void Gfx::cacheTileSequence(int tileIndex, int count) { void Gfx::cacheTileSequence(int tileIndex, int count) {
for (int i = tileIndex; i < tileIndex + count; i++) for (int i = tileIndex; i < tileIndex + count; i++)
getTile(i); g_hdb->_ai->_animTiles.push_back(getTile(i));
} }
int Gfx::getTileIndex(const char *name) { int Gfx::getTileIndex(const char *name) {

View File

@ -79,6 +79,7 @@ HDBGame::~HDBGame() {
delete _fileMan; delete _fileMan;
delete _gfx; delete _gfx;
delete _lua; delete _lua;
delete _menu;
delete _map; delete _map;
delete _ai; delete _ai;
delete _input; delete _input;