From 48413a924275499f81296d48b6155d433ab122d6 Mon Sep 17 00:00:00 2001 From: Wanne Date: Sun, 3 Jan 2016 11:43:38 +0000 Subject: [PATCH] Fix: Fixed crash, when clicking on "Done" button after "Auto Resolve" has been finished (pGroup NULL pointer) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8008 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Strategic Movement.cpp | 33 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Strategic/Strategic Movement.cpp b/Strategic/Strategic Movement.cpp index 74462151..6a9223d5 100644 --- a/Strategic/Strategic Movement.cpp +++ b/Strategic/Strategic Movement.cpp @@ -4770,25 +4770,28 @@ void ResetMovementForNonPlayerGroup( GROUP *pGroup ) { if ( pGroup->ubSectorX == pOtherGroup->ubSectorX && pGroup->ubSectorY == pOtherGroup->ubSectorY ) { - MoveSAIGroupToSector( &pGroup, (UINT8)SECTOR( pOtherGroup->ubNextX, pOtherGroup->ubNextY ), DIRECT, PURSUIT ); - - // the group has to be delayed - otherwise they could arrive at the same time as the player, resulting in odd behaviour during insertion - if ( pGroup->uiArrivalTime < min( pGroup->uiArrivalTime, pOtherGroup->uiArrivalTime ) + 5 ) + if (pGroup != NULL) { - DeleteStrategicEvent( EVENT_GROUP_ARRIVAL, pGroup->ubGroupID ); + MoveSAIGroupToSector( &pGroup, (UINT8)SECTOR( pOtherGroup->ubNextX, pOtherGroup->ubNextY ), DIRECT, PURSUIT ); - // NOTE: This can cause the arrival time to be > GetWorldTotalMin() + TraverseTime, so keep that in mind - // if you have any code that uses these 3 values to figure out how far along its route a group is! - SetGroupArrivalTime( pGroup, pOtherGroup->uiArrivalTime + 5 ); - - if ( !AddStrategicEvent( EVENT_GROUP_ARRIVAL, pGroup->uiArrivalTime, pGroup->ubGroupID ) ) + // the group has to be delayed - otherwise they could arrive at the same time as the player, resulting in odd behaviour during insertion + if (pGroup != NULL && pGroup->uiArrivalTime < min( pGroup->uiArrivalTime, pOtherGroup->uiArrivalTime ) + 5 ) { - AssertMsg( 0, "Failed to add movement event." ); - break; - } - } + DeleteStrategicEvent( EVENT_GROUP_ARRIVAL, pGroup->ubGroupID ); - sucess = TRUE; + // NOTE: This can cause the arrival time to be > GetWorldTotalMin() + TraverseTime, so keep that in mind + // if you have any code that uses these 3 values to figure out how far along its route a group is! + SetGroupArrivalTime( pGroup, pOtherGroup->uiArrivalTime + 5 ); + + if ( !AddStrategicEvent( EVENT_GROUP_ARRIVAL, pGroup->uiArrivalTime, pGroup->ubGroupID ) ) + { + AssertMsg( 0, "Failed to add movement event." ); + break; + } + } + + sucess = TRUE; + } break; }