diff --git a/radiantcore/selection/SceneWalkers.h b/radiantcore/selection/SceneWalkers.h index c21a0691d5..07d2a3e968 100644 --- a/radiantcore/selection/SceneWalkers.h +++ b/radiantcore/selection/SceneWalkers.h @@ -46,32 +46,37 @@ class RemoveDegenerateBrushWalker : mutable std::list _eraseList; public: // Destructor removes marked paths - ~RemoveDegenerateBrushWalker() { - for (std::list::iterator i = _eraseList.begin(); i != _eraseList.end(); ++i) { - // Check if the parent has any children left at all - scene::INodePtr parent = (*i)->getParent(); - - // Remove the node from the scene - scene::removeNodeFromParent(*i); - - if (parent != NULL && !parent->hasChildNodes()) { - rError() << "Warning: removing empty parent entity." << std::endl; - scene::removeNodeFromParent(parent); - } - } + ~RemoveDegenerateBrushWalker() override + { + for (const auto& node : _eraseList) + { + // Check if the parent has any children left at all + auto parent = node->getParent(); + + // Remove the node from the scene + removeNodeFromParent(node); + + if (parent && !parent->hasChildNodes()) + { + rError() << "Warning: removing empty parent entity." << std::endl; + removeNodeFromParent(parent); + } + } } - void visit(const scene::INodePtr& node) const + void visit(const scene::INodePtr& node) const override { - Brush* brush = Node_getBrush(node); - - if (brush != NULL && !brush->hasContributingFaces()) + if (auto brush = Node_getBrush(node); brush) { - // greebo: Mark this path for removal - _eraseList.push_back(node); + brush->evaluateBRep(); - rError() << "Warning: removed degenerate brush!\n"; - return; + if (!brush->hasContributingFaces()) + { + // greebo: Mark this path for removal + _eraseList.push_back(node); + + rError() << "Warning: removed degenerate brush!\n"; + } } } }; diff --git a/radiantcore/selection/algorithm/General.cpp b/radiantcore/selection/algorithm/General.cpp index 261ac57c42..69d80ebcf7 100644 --- a/radiantcore/selection/algorithm/General.cpp +++ b/radiantcore/selection/algorithm/General.cpp @@ -730,9 +730,7 @@ void snapSelectionToGrid(const cmd::ArgumentList& args) if (!node->visible()) return; // Check if the visited instance is componentSnappable - ComponentSnappablePtr componentSnappable = Node_getComponentSnappable(node); - - if (componentSnappable) + if (auto componentSnappable = Node_getComponentSnappable(node); componentSnappable) { componentSnappable->snapComponents(gridSize); } @@ -746,14 +744,15 @@ void snapSelectionToGrid(const cmd::ArgumentList& args) // Don't do anything with hidden nodes if (!node->visible()) return; - SnappablePtr snappable = Node_getSnappable(node); - - if (snappable) + if (auto snappable = Node_getSnappable(node); snappable) { snappable->snapto(gridSize); } }); } + + // Remove all degenerated brushes after this operation + GlobalSelectionSystem().foreachSelected(RemoveDegenerateBrushWalker()); } class IntersectionFinder :