Core: Fix crash in ActiveObjectList

Forum: https://forum.freecad.org/viewtopic.php?t=91823
This commit is contained in:
wmayer
2024-11-03 19:22:15 +01:00
committed by wwmayer
parent ab0b63e1e3
commit 62d504d0a1

View File

@@ -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;
}
}
}