diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp index 6c323c786f5..8e53b6491fe 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp @@ -291,6 +291,11 @@ void LaserUpdate::initLaser( const Object *parent, const Coord3D *startPos, cons { system->setPosition( &m_startPos ); } + else + { + // Particle system no longer exists; clear the stale ID to prevent future access violations. + m_particleSystemID = INVALID_PARTICLE_SYSTEM_ID; + } } if( m_targetParticleSystemID ) { @@ -299,6 +304,11 @@ void LaserUpdate::initLaser( const Object *parent, const Coord3D *startPos, cons { system->setPosition( &m_endPos ); } + else + { + // Particle system no longer exists; clear the stale ID to prevent future access violations. + m_targetParticleSystemID = INVALID_PARTICLE_SYSTEM_ID; + } } //Important! Set the laser position to the average of both points or else diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp index 5214a726b5f..e8bd76f831d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp @@ -392,6 +392,11 @@ void LaserUpdate::initLaser( const Object *parent, const Object *target, const C { system->setPosition( &m_startPos ); } + else + { + // Particle system no longer exists; clear the stale ID to prevent future access violations. + m_particleSystemID = INVALID_PARTICLE_SYSTEM_ID; + } } //PLEASE NOTE You cannot check an ID for nullptr. This should be a check against INVALID_PARTICLE_SYSTEM_ID. Can't change it on the last day without a bug though. @@ -402,6 +407,11 @@ void LaserUpdate::initLaser( const Object *parent, const Object *target, const C { system->setPosition( &m_endPos ); } + else + { + // Particle system no longer exists; clear the stale ID to prevent future access violations. + m_targetParticleSystemID = INVALID_PARTICLE_SYSTEM_ID; + } } //Important! Set the laser position to the average of both points or else