diff --git a/source/games/sw/src/lists.h b/source/games/sw/src/lists.h index e3a98e98e51..bb497139507 100644 --- a/source/games/sw/src/lists.h +++ b/source/games/sw/src/lists.h @@ -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; \ diff --git a/source/games/sw/src/panel.cpp b/source/games/sw/src/panel.cpp index eb4af4ee562..c552ca962a6 100644 --- a/source/games/sw/src/panel.cpp +++ b/source/games/sw/src/panel.cpp @@ -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); } }