diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp index c308227060..bfcd609550 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -2168,6 +2168,15 @@ void Object::onCollide( Object *other, const Coord3D *loc, const Coord3D *normal #endif break; } + + // If this object or the other object has been destroyed by a previous + // collide module handler, stop processing further modules to avoid + // accessing freed/invalid memory (null pointer dereference). + if( isDestroyed() ) + break; + if( other != nullptr && other->isDestroyed() ) + break; + #ifdef DEBUG_CRC //DEBUG_LOG(("Object::onCollide() - calling collide module")); #endif diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp index ffb8684fa7..3ab49eecee 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -2445,6 +2445,15 @@ void Object::onCollide( Object *other, const Coord3D *loc, const Coord3D *normal #endif break; } + + // If this object or the other object has been destroyed by a previous + // collide module handler, stop processing further modules to avoid + // accessing freed/invalid memory (null pointer dereference). + if( isDestroyed() ) + break; + if( other != nullptr && other->isDestroyed() ) + break; + #ifdef DEBUG_CRC //DEBUG_LOG(("Object::onCollide() - calling collide module")); #endif