diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 7a858405d6e..38552383104 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -1634,13 +1634,19 @@ ObjectShroudStatus PartitionData::getShroudedStatus(Int playerIndex) #endif Int shroudedCells = 0; Int foggedCells = 0; - CellAndObjectIntersection* coi = m_coiArray; - for (Int i = m_coiInUseCount; i; --i, ++coi) + + // Check if m_coiArray is valid before accessing it to prevent null pointer dereference + // This can occur when orphaned ghost objects have their partition data released + if (m_coiArray != NULL) { - if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_SHROUDED ) - ++shroudedCells; - else if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_FOGGED ) - ++foggedCells; + CellAndObjectIntersection* coi = m_coiArray; + for (Int i = m_coiInUseCount; i; --i, ++coi) + { + if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_SHROUDED ) + ++shroudedCells; + else if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_FOGGED ) + ++foggedCells; + } } if( m_coiInUseCount == 0 ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 8c0830f3f12..e5302b47276 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -1638,13 +1638,19 @@ ObjectShroudStatus PartitionData::getShroudedStatus(Int playerIndex) #endif Int shroudedCells = 0; Int foggedCells = 0; - CellAndObjectIntersection* coi = m_coiArray; - for (Int i = m_coiInUseCount; i; --i, ++coi) + + // Check if m_coiArray is valid before accessing it to prevent null pointer dereference + // This can occur when orphaned ghost objects have their partition data released + if (m_coiArray != NULL) { - if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_SHROUDED ) - ++shroudedCells; - else if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_FOGGED ) - ++foggedCells; + CellAndObjectIntersection* coi = m_coiArray; + for (Int i = m_coiInUseCount; i; --i, ++coi) + { + if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_SHROUDED ) + ++shroudedCells; + else if( coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_FOGGED ) + ++foggedCells; + } } if( m_coiInUseCount == 0 )