From 05cd8e112842983526b72569d44dcdc90cc41eec Mon Sep 17 00:00:00 2001 From: Joep Jansen Date: Sun, 7 Nov 2021 19:36:35 +0100 Subject: [PATCH] Fix Gazebo crash in building editor when adding door or window (#2276) BuildingMaker::DetachFromParent: break loop after DetachAllChildren. Prevents memory corruption by iterating over attachmentMap while removing elements. --- gazebo/gui/building/BuildingMaker.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gazebo/gui/building/BuildingMaker.cc b/gazebo/gui/building/BuildingMaker.cc index 5e225532fb..21de7ec310 100644 --- a/gazebo/gui/building/BuildingMaker.cc +++ b/gazebo/gui/building/BuildingMaker.cc @@ -228,8 +228,10 @@ void BuildingMaker::DetachFromParent(const std::string &_child) parentManip.second.erase(std::remove(parentManip.second.begin(), parentManip.second.end(), _child), parentManip.second.end()); - if (parentManip.second.empty()) + if (parentManip.second.empty()) { this->DetachAllChildren(parentManip.first); + break; + } } }