- SW: avoid crashing when unwinding from a savegame loading error.

The linked list may be incomplete in this case.
Also kept the macro unmangling done to debug this code.
This commit is contained in:
Christoph Oelckers 2021-08-30 13:57:58 +02:00
parent 3c3da13d3f
commit e13426ec6e
2 changed files with 8 additions and 4 deletions

View file

@ -56,9 +56,11 @@ typedef
((LIST) list)->Prev = (LIST) nodep, \
((LIST) nodep)->Prev->Next = (LIST) nodep)
#define REMOVE(nodep) ( ((LIST) nodep)->Prev->Next = ((LIST) nodep)->Next, \
((LIST) nodep)->Next->Prev = ((LIST) nodep)->Prev)
inline void REMOVE(PANEL_SPRITEp nodep)
{
nodep->Prev->Next = nodep->Next;
nodep->Next->Prev = nodep->Prev;
}
#define TRAVERSE(l, o, n) ASSERT(((LIST)l)->Next && ((LIST)l)->Prev); for (o = (decltype(o))(((LIST)l)->Next); \
n = o->Next, (LIST) o != (LIST) l; \

View file

@ -6513,9 +6513,11 @@ void
pClearSpriteList(PLAYERp pp)
{
PANEL_SPRITEp psp=nullptr, next_psp=nullptr;
auto l = &pp->PanelSpriteList;
TRAVERSE(&pp->PanelSpriteList, psp, next_psp)
for (psp = l->Next; next_psp = psp->Next, (LIST)psp != (LIST)l; psp = next_psp)
{
if (psp->Next == nullptr || psp->Prev == nullptr) return; // this can happen when cleaning up a fatal error.
pKillSprite(psp);
}
}