From 62d504d0a1a7d853287b61cd458cbf45ceb0a548 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 3 Nov 2024 19:22:15 +0100 Subject: [PATCH] Core: Fix crash in ActiveObjectList Forum: https://forum.freecad.org/viewtopic.php?t=91823 --- src/Gui/ActiveObjectList.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Gui/ActiveObjectList.cpp b/src/Gui/ActiveObjectList.cpp index 717a65ad2b..0fc064cdb6 100644 --- a/src/Gui/ActiveObjectList.cpp +++ b/src/Gui/ActiveObjectList.cpp @@ -184,11 +184,16 @@ bool Gui::ActiveObjectList::hasObject(const char*name)const void ActiveObjectList::objectDeleted(const ViewProviderDocumentObject &vp) { - //maybe boost::bimap or boost::multi_index - for (auto it = _ObjectMap.begin(); it != _ObjectMap.end(); ++it) { - if (it->second.obj == vp.getObject()) { - _ObjectMap.erase(it); - return; + // Hint: With C++20 std::erase_if for containers can be used + auto isEqual = [&vp](const auto& item) { + return item.second.obj == vp.getObject(); + }; + for (auto it = _ObjectMap.begin(); it != _ObjectMap.end();) { + if (isEqual(*it)) { + it = _ObjectMap.erase(it); + } + else { + ++it; } } }