diff options
author | Freeyorp <TheFreeYorp+git@gmail.com> | 2024-04-21 06:43:43 +0000 |
---|---|---|
committer | Freeyorp <TheFreeYorp+git@gmail.com> | 2024-04-21 06:44:20 +0000 |
commit | ae2556ec8fcbfed9e18d275a578f4bc47d26f721 (patch) | |
tree | e719063551edf29f31b77c1e54bfd31396f860d1 /src | |
parent | 3f214c06c13dfc4c4eb42a3f24553d7a1d30b26d (diff) | |
download | tmwa-ae2556ec8fcbfed9e18d275a578f4bc47d26f721.tar.gz tmwa-ae2556ec8fcbfed9e18d275a578f4bc47d26f721.tar.bz2 tmwa-ae2556ec8fcbfed9e18d275a578f4bc47d26f721.tar.xz tmwa-ae2556ec8fcbfed9e18d275a578f4bc47d26f721.zip |
DB: Maybe fix concurrent modification
Diffstat (limited to 'src')
-rw-r--r-- | src/generic/db.hpp | 4 | ||||
-rw-r--r-- | 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<bool(const std::pair<K, V>&)> 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<npc_data> 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_(); |