Skip to content

Commit c505de1

Browse files
ScriptEngine: Check for NULL object pointer before returning from GetNamedObject
1 parent 9f7a45e commit c505de1

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5284,7 +5284,13 @@ Object * ScriptEngine::getUnitNamed(const AsciiString& unitName)
52845284

52855285
for (VecNamedRequestsIt it = m_namedObjects.begin(); it != m_namedObjects.end(); ++it) {
52865286
if (unitName == (it->first)) {
5287-
return it->second;
5287+
// Check if the object pointer is valid before returning it
5288+
// Objects can be deleted but remain in cache with NULL pointer
5289+
if (it->second != NULL) {
5290+
return it->second;
5291+
}
5292+
// Object was deleted, return NULL
5293+
return NULL;
52885294
}
52895295
}
52905296
return NULL;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6033,7 +6033,13 @@ Object* ScriptEngine::getUnitNamed(const AsciiString& unitName)
60336033

60346034
for (VecNamedRequestsIt it = m_namedObjects.begin(); it != m_namedObjects.end(); ++it) {
60356035
if (unitName == (it->first)) {
6036-
return it->second;
6036+
// Check if the object pointer is valid before returning it
6037+
// Objects can be deleted but remain in cache with NULL pointer
6038+
if (it->second != NULL) {
6039+
return it->second;
6040+
}
6041+
// Object was deleted, return NULL
6042+
return NULL;
60376043
}
60386044
}
60396045
return NULL;

0 commit comments

Comments
 (0)