From fc7f558786de77c880558b70dd689cdc4b385b6f Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:56:14 +0000 Subject: [PATCH] bugfix(gameengine): Prevent crash when OCL source object is null or destroyed --- .../Source/GameLogic/Object/ObjectCreationList.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 94eeca8604..1a20dc9a49 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -1196,7 +1196,16 @@ class GenericObjectCreationNugget : public ObjectCreationNugget if( m_containInsideSourceObject ) { // The Obj has been totally made, so stuff it inside ourselves if desired. - if( sourceObj->getContain() && sourceObj->getContain()->isValidContainerFor(obj, TRUE)) + // Guard against sourceObj being null or already destroyed (e.g. when this OCL fires + // from a CreateObjectDie handler -- the dying object may be in the process of being + // deleted, making the pointer dangling/invalid). + if( !sourceObj || sourceObj->isDestroyed() ) + { + DEBUG_CRASH(("A OCL with ContainInsideSourceObject has a null or already-destroyed sourceObj and is killing the new object.")); + // If the source object is gone, we can't contain the new object. Stillborn it. + TheGameLogic->destroyObject(obj); + } + else if( sourceObj->getContain() && sourceObj->getContain()->isValidContainerFor(obj, TRUE)) { sourceObj->getContain()->addToContain( obj );