Skip to content

Commit

Permalink
- SW: avoid crashing when unwinding from a savegame loading error.
Browse files Browse the repository at this point in the history
The linked list may be incomplete in this case.
Also kept the macro unmangling done to debug this code.
  • Loading branch information
coelckers committed Sep 12, 2021
1 parent 3c3da13 commit e13426e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions source/games/sw/src/lists.h
Expand Up @@ -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; \
Expand Down
4 changes: 3 additions & 1 deletion source/games/sw/src/panel.cpp
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit e13426e

Please sign in to comment.