From 388dd5cb00dde2053c7eb488c13d608a70ba330c Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Mon, 26 Jul 2021 19:23:37 -0700 Subject: Allow sector ped count to exceed gap-list size This solves the gnNumTempPedList assertion. To prove this works, change gapTempPedList's length to 12, and visit the Triad's basketball court. --- src/peds/Ped.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 4d80cac2..4c47ee7c 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -392,8 +392,21 @@ CPed::BuildPedLists(void) if (ped != this && !ped->bInVehicle) { float dist = (ped->GetPosition() - GetPosition()).Magnitude2D(); if (nThreatReactionRangeMultiplier * 30.0f > dist) { +#ifdef FIX_BUGS + static_assert( ARRAY_SIZE(m_nearPeds) < ARRAY_SIZE(gapTempPedList) - 1, "gapTempPedList needs wiggle room for unsorted peds and nil slot" ); + // If the gap ped list is full, sort it and truncate it + // before pushing more unsorted peds + if( gnNumTempPedList == ARRAY_SIZE(gapTempPedList) - 1 ) + { + gapTempPedList[gnNumTempPedList] = nil; + SortPeds(gapTempPedList, 0, gnNumTempPedList - 1); + gnNumTempPedList = ARRAY_SIZE(m_nearPeds); + } +#endif + gapTempPedList[gnNumTempPedList] = ped; gnNumTempPedList++; + // NOTE: We cannot absolutely fill the gap list, as the list is null-terminated before being passed to SortPeds assert(gnNumTempPedList < ARRAY_SIZE(gapTempPedList)); } } -- cgit v1.2.3 From 55e83982c31a18474a7789f1a966a25934ad37f8 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Tue, 27 Jul 2021 00:22:10 -0700 Subject: Remove static_assert from previous commit --- src/peds/Ped.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 4c47ee7c..5a72f288 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -393,7 +393,6 @@ CPed::BuildPedLists(void) float dist = (ped->GetPosition() - GetPosition()).Magnitude2D(); if (nThreatReactionRangeMultiplier * 30.0f > dist) { #ifdef FIX_BUGS - static_assert( ARRAY_SIZE(m_nearPeds) < ARRAY_SIZE(gapTempPedList) - 1, "gapTempPedList needs wiggle room for unsorted peds and nil slot" ); // If the gap ped list is full, sort it and truncate it // before pushing more unsorted peds if( gnNumTempPedList == ARRAY_SIZE(gapTempPedList) - 1 ) -- cgit v1.2.3