From ae2556ec8fcbfed9e18d275a578f4bc47d26f721 Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Sun, 21 Apr 2024 06:43:43 +0000 Subject: DB: Maybe fix concurrent modification --- src/generic/db.hpp | 4 ++++ src/map/npc.cpp | 10 +++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/generic/db.hpp b/src/generic/db.hpp index 04ead79..d610f32 100644 --- a/src/generic/db.hpp +++ b/src/generic/db.hpp @@ -78,6 +78,10 @@ public: { return borrow(impl[k]); } + void erase_if(std::function&)> predicate) + { + std::erase_if(impl, predicate); + } void erase(const K& k) { impl.erase(k); diff --git a/src/map/npc.cpp b/src/map/npc.cpp index efb2ba3..76f0e14 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -1053,13 +1053,9 @@ void npc_free_internal(dumb_ptr nd_) // Also clean up any events we registered to the global ev_db if (auto nd = nd_->is_script()) { - for (auto& pair : ev_db) - { - if (pair.second.nd == nd) - { - ev_db.erase(pair.first); - } - } + ev_db.erase_if([&](auto& pair) { + return pair.second.nd == nd; + }); } nd_.delete_(); -- cgit v1.2.3-70-g09d2