diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index f5bef922a..6c41608a8 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -732,6 +732,8 @@ void CNpcEnemy::init() setCollisionCentreOffset( 0, -( ofs.vy >> 1 ) ); m_positionHistory = NULL; + + m_isShuttingDown = false; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -777,33 +779,38 @@ void CNpcEnemy::reinit() void CNpcEnemy::shutdown() { - if (m_spriteBank) m_spriteBank->dump(); delete m_spriteBank; - // remove waypoints - - m_npcPath.removeAllWaypoints(); - - // remove position history - - CNpcPositionHistory *currentPosition; - CNpcPositionHistory *oldPosition; - - currentPosition = m_positionHistory; - - while( currentPosition ) + if ( !m_isShuttingDown ) { - oldPosition = currentPosition; - currentPosition = currentPosition->next; + m_isShuttingDown = true; - delete oldPosition; + if (m_spriteBank) m_spriteBank->dump(); delete m_spriteBank; + // remove waypoints + + m_npcPath.removeAllWaypoints(); + + // remove position history + + CNpcPositionHistory *currentPosition; + CNpcPositionHistory *oldPosition; + + currentPosition = m_positionHistory; + + while( currentPosition ) + { + oldPosition = currentPosition; + currentPosition = currentPosition->next; + + delete oldPosition; + } + + m_positionHistory = NULL; + + if (m_actorGfx) delete m_actorGfx; + + deleteAllChild(); + + CEnemyThing::shutdown(); } - - m_positionHistory = NULL; - - if (m_actorGfx) delete m_actorGfx; - - deleteAllChild(); - - CEnemyThing::shutdown(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/enemy/npc.h b/source/enemy/npc.h index 0fd5305b1..08d6bc442 100644 --- a/source/enemy/npc.h +++ b/source/enemy/npc.h @@ -355,6 +355,8 @@ protected: virtual void collidedWith(CThing *_thisThing); + u8 m_isShuttingDown; + // position history stuff class CNpcPositionHistory diff --git a/source/projectl/projectl.cpp b/source/projectl/projectl.cpp index 9d163810e..8b9b36473 100644 --- a/source/projectl/projectl.cpp +++ b/source/projectl/projectl.cpp @@ -64,6 +64,7 @@ void CProjectile::init() m_state = PROJECTILE_ATTACK; m_turnSpeed = 256; m_extension = 0; + m_isShuttingDown = false; } void CProjectile::init( DVECTOR initPos, s16 initHeading ) @@ -91,9 +92,14 @@ void CProjectile::init( DVECTOR initPos, s16 initHeading, PROJECTILE_MOVEMENT_TY void CProjectile::shutdown() { - m_spriteBank->dump(); delete m_spriteBank; + if ( !m_isShuttingDown ) + { + m_isShuttingDown = true; - CEnemyProjectileThing::shutdown(); + m_spriteBank->dump(); delete m_spriteBank; + + CEnemyProjectileThing::shutdown(); + } } bool CProjectile::processTargetSeek( int _frames, DVECTOR targetPos ) @@ -237,7 +243,6 @@ void CProjectile::think(int _frames) if ( m_layerCollision->Get( Pos.vx >> 4, Pos.vy >> 4 ) ) { shutdown(); - delete this; } else { @@ -298,7 +303,6 @@ void CProjectile::think(int _frames) if ( m_layerCollision->Get( Pos.vx >> 4, Pos.vy >> 4 ) ) { shutdown(); - delete this; } else { @@ -317,7 +321,6 @@ void CProjectile::think(int _frames) if ( m_lifetime <= 0 ) { shutdown(); - delete this; } } } @@ -373,7 +376,6 @@ void CProjectile::collidedWith(CThing *_thisThing) if ( m_lifetimeType != PROJECTILE_INFINITE_LIFE ) { shutdown(); - delete this; } break; @@ -434,9 +436,14 @@ void CPlayerProjectile::init( DVECTOR initPos, s16 initHeading, PLAYER_PROJECTIL void CPlayerProjectile::shutdown() { - m_spriteBank->dump(); delete m_spriteBank; + if ( !m_isShuttingDown ) + { + m_isShuttingDown = true; - CPlayerProjectileThing::shutdown(); + m_spriteBank->dump(); delete m_spriteBank; + + CPlayerProjectileThing::shutdown(); + } } void CPlayerProjectile::setMovementType( PLAYER_PROJECTILE_MOVEMENT_TYPE moveType ) @@ -478,7 +485,6 @@ void CPlayerProjectile::think(int _frames) if ( m_layerCollision->Get( Pos.vx >> 4, Pos.vy >> 4 ) ) { shutdown(); - delete this; } else { @@ -497,7 +503,6 @@ void CPlayerProjectile::think(int _frames) if ( m_lifetime <= 0 ) { shutdown(); - delete this; } } } diff --git a/source/projectl/projectl.h b/source/projectl/projectl.h index 032698357..9d54fb0bb 100644 --- a/source/projectl/projectl.h +++ b/source/projectl/projectl.h @@ -75,6 +75,7 @@ protected: PROJECTILE_LIFETIME_TYPE m_lifetimeType; PROJECTILE_STATE m_state; u16 m_turnSpeed; + u8 m_isShuttingDown; }; /*****************************************************************************/ @@ -125,6 +126,7 @@ protected: int m_frame; POLY_FT4 *SprFrame; u8 m_reversed; + u8 m_isShuttingDown; }; diff --git a/source/thing/thing.cpp b/source/thing/thing.cpp index 740d266b3..16b4762a6 100644 --- a/source/thing/thing.cpp +++ b/source/thing/thing.cpp @@ -360,13 +360,11 @@ void CThingManager::addToThingList(CThing *_this) Params: Returns: ---------------------------------------------------------------------- */ -int testTypeGit; void CThingManager::removeFromThingList(CThing *_this) { CThing *prevThing,*thing; prevThing=NULL; - testTypeGit = _this->getThingType(); thing=s_thingLists[_this->getThingType()]; while(thing!=_this) {