Skip to content
This repository has been archived by the owner. It is now read-only.

Fix bug triggering gnNumTempPedList assertion #1257

Merged
merged 2 commits into from Jul 27, 2021
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

Next
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.
  • Loading branch information
Nopey committed Jul 27, 2021
commit 388dd5cb00dde2053c7eb488c13d608a70ba330c
@@ -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" );

This comment has been minimized.

@erorcun

erorcun Jul 27, 2021
Collaborator

This is a thing since C++11, so it's not allowed here, sorry.

This comment has been minimized.

@Nopey

Nopey Jul 27, 2021
Author Contributor

core\common.h
368:#define static_assert(bool_constexpr, message)
376:    static_assert(s == t, "Invalid structure size");

It's both defined and used in common.h

// If the gap ped list is full, sort it and truncate it
// before pushing more unsorted peds
if( gnNumTempPedList == ARRAY_SIZE(gapTempPedList) - 1 )

This comment has been minimized.

@erorcun

erorcun Jul 27, 2021
Collaborator

Instead of doing this, you can break all loops. It's clear that it can't continue further this point, because gapTempPedList will be full.

{
gapTempPedList[gnNumTempPedList] = nil;
SortPeds(gapTempPedList, 0, gnNumTempPedList - 1);
gnNumTempPedList = ARRAY_SIZE(m_nearPeds);

This comment has been minimized.

@erorcun

erorcun Jul 27, 2021
Collaborator

Why? m_nearPeds isn't used in this loop at all

}

This comment has been minimized.

@erorcun

erorcun Jul 27, 2021
Collaborator

Why don't you break here? It's clear that it can't continue anymore.

#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));
}
}