Skip to content

Commit 3592020

Browse files
committed
Made showNext safer and more stable (I suppose)
1 parent 780b9fa commit 3592020

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

source/am_map.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,14 @@ static void AM_moveCenterToPoint(v2fixed_t point)
11241124
AM_changeWindowLoc();
11251125
}
11261126

1127+
static inline bool IsThinkerInList(const Thinker *candidate)
1128+
{
1129+
for(Thinker *itr = thinkercap.next; itr != &thinkercap; itr = itr->next)
1130+
if(itr == candidate)
1131+
return true;
1132+
return false;
1133+
}
1134+
11271135
//
11281136
// Used by player cheat codes to find tally-relevant objects on the map.
11291137
//
@@ -1150,6 +1158,11 @@ void MobjLookupCheat::showNext(type_e type)
11501158
const Thinker *start_th;
11511159
Thinker *th;
11521160

1161+
// Validate current thinker, if any, to allow for the possibility that it was removed from the map since the last
1162+
// call
1163+
if(current && !IsThinkerInList(static_cast<Thinker *>(current)))
1164+
current = nullptr;
1165+
11531166
if(current)
11541167
start_th = th = static_cast<Thinker *>(current);
11551168
else
@@ -1159,6 +1172,9 @@ void MobjLookupCheat::showNext(type_e type)
11591172
{
11601173
th = th->next;
11611174

1175+
if(!th)
1176+
break;
1177+
11621178
Mobj *mo = thinker_cast<Mobj *>(th);
11631179

11641180
if(mo && (!mustBeAlive || mo->health > 0) && mo->flags & flags)

0 commit comments

Comments
 (0)