Skip to content

Commit 286e8f3

Browse files
bugfix(object): Prevent null pointer dereference in onCollide after object destruction
1 parent 8e29982 commit 286e8f3

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object
  • Generals/Code/GameEngine/Source/GameLogic/Object

Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,15 @@ void Object::onCollide( Object *other, const Coord3D *loc, const Coord3D *normal
21682168
#endif
21692169
break;
21702170
}
2171+
2172+
// If this object or the other object has been destroyed by a previous
2173+
// collide module handler, stop processing further modules to avoid
2174+
// accessing freed/invalid memory (null pointer dereference).
2175+
if( isDestroyed() )
2176+
break;
2177+
if( other != nullptr && other->isDestroyed() )
2178+
break;
2179+
21712180
#ifdef DEBUG_CRC
21722181
//DEBUG_LOG(("Object::onCollide() - calling collide module"));
21732182
#endif

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,15 @@ void Object::onCollide( Object *other, const Coord3D *loc, const Coord3D *normal
24452445
#endif
24462446
break;
24472447
}
2448+
2449+
// If this object or the other object has been destroyed by a previous
2450+
// collide module handler, stop processing further modules to avoid
2451+
// accessing freed/invalid memory (null pointer dereference).
2452+
if( isDestroyed() )
2453+
break;
2454+
if( other != nullptr && other->isDestroyed() )
2455+
break;
2456+
24482457
#ifdef DEBUG_CRC
24492458
//DEBUG_LOG(("Object::onCollide() - calling collide module"));
24502459
#endif

0 commit comments

Comments
 (0)