From aa18dae077ea0a0cbf86b64c0b8b80b8bd0adcaa Mon Sep 17 00:00:00 2001 From: Pavel Solodovnikov Date: Sat, 14 Sep 2024 14:01:10 +0300 Subject: [PATCH] objmem: properly check for missing elements in `freeAllEntitiesImpl` It's forbidden to invoke `.erase()` on the end iterator, so avoid calling the method by guarding this code path by a `continue` + `ASSERT` combination. Signed-off-by: Pavel Solodovnikov --- src/objmem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/objmem.cpp b/src/objmem.cpp index 4a07fd8eb91..388dd524bf1 100644 --- a/src/objmem.cpp +++ b/src/objmem.cpp @@ -589,7 +589,10 @@ static void freeAllEntitiesImpl(PerPlayerObjectLists& entit for (auto* ent : list) { auto it = entityContainer.find(*ent); - ASSERT(it != entityContainer.end(), "%s not found in the global container!", Traits::entityName()); + if (it == entityContainer.end()) { + ASSERT(false, "%s not found in the global container!", Traits::entityName()); + continue; + } entityContainer.erase(it); } list.clear();