diff --git a/Components/Overlay/src/OgreOverlayProfileSessionListener.cpp b/Components/Overlay/src/OgreOverlayProfileSessionListener.cpp index 8b210c1f0b9..81b94a45609 100644 --- a/Components/Overlay/src/OgreOverlayProfileSessionListener.cpp +++ b/Components/Overlay/src/OgreOverlayProfileSessionListener.cpp @@ -110,11 +110,10 @@ namespace Ogre OverlayContainer* container = dynamic_cast(mProfileGui); if (container) { - for (const auto& p : container->getChildren()) + while (!container->getChildren().empty()) { - OverlayElement* element = p.second; - OverlayContainer* parent = element->getParent(); - if (parent) parent->removeChild(element->getName()); + OverlayElement* element = container->getChildren().cbegin()->second; + container->removeChild(element->getName()); OverlayManager::getSingleton().destroyOverlayElement(element); } }