From 448450e6e8d28257e2e23af9cc21fbc1db8bd185 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Sat, 25 Oct 2025 09:57:34 +0000 Subject: [PATCH] PartitionManager: Add null check for m_coiArray before accessing it --- .../GameLogic/Object/PartitionManager.cpp | 18 ++++++++++++------ .../GameLogic/Object/PartitionManager.cpp | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) 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 )