From c505de1ca9972e3071abf0cf051976d610d95360 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Tue, 11 Nov 2025 15:30:14 +0000 Subject: [PATCH] ScriptEngine: Check for NULL object pointer before returning from GetNamedObject --- .../Source/GameLogic/ScriptEngine/ScriptEngine.cpp | 8 +++++++- .../Source/GameLogic/ScriptEngine/ScriptEngine.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index 4dee735b3fa..f8c5bc67679 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -5284,7 +5284,13 @@ Object * ScriptEngine::getUnitNamed(const AsciiString& unitName) for (VecNamedRequestsIt it = m_namedObjects.begin(); it != m_namedObjects.end(); ++it) { if (unitName == (it->first)) { - return it->second; + // Check if the object pointer is valid before returning it + // Objects can be deleted but remain in cache with NULL pointer + if (it->second != NULL) { + return it->second; + } + // Object was deleted, return NULL + return NULL; } } return NULL; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index 9574bf30983..2ac5e702fb3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -6033,7 +6033,13 @@ Object* ScriptEngine::getUnitNamed(const AsciiString& unitName) for (VecNamedRequestsIt it = m_namedObjects.begin(); it != m_namedObjects.end(); ++it) { if (unitName == (it->first)) { - return it->second; + // Check if the object pointer is valid before returning it + // Objects can be deleted but remain in cache with NULL pointer + if (it->second != NULL) { + return it->second; + } + // Object was deleted, return NULL + return NULL; } } return NULL;