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;