From 8095904bc2cf4a8c42aa467e6bc23603d9ef5737 Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Wed, 23 Sep 2026 12:15:19 +0800 Subject: [PATCH] Catch Only Allocation and Thread Failures Around the Shell Classification The fallback that marks every segment as shell caught everything, which would also have hidden a logic error. It now catches what the classification can really throw on a huge print: std::bad_alloc from its grids and std::system_error from a worker thread that cannot be launched. --- src/libvgcode/src/ViewerImpl.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libvgcode/src/ViewerImpl.cpp b/src/libvgcode/src/ViewerImpl.cpp index 743412c38e..b23cb1b0af 100644 --- a/src/libvgcode/src/ViewerImpl.cpp +++ b/src/libvgcode/src/ViewerImpl.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1722,16 +1723,23 @@ void ViewerImpl::update_enabled_entities() // the shell is classified once per load, the first time it is needed const bool shell_reduced = reduced_mode == EReducedDetailMode::ShellOnly; if (shell_reduced && m_shell_bitset.size != m_vertices.size()) { - try { - update_shell_bitset(); - } - catch (...) { - // out of memory on a huge print: take everything for shell, which leaves out only the hidden infill + const auto fallback = [this]() { m_shell_bitset = BitSet<>(m_vertices.size()); m_shell_bitset.setAll(); m_near_shell_bitset = BitSet<>(m_vertices.size()); m_top_visible_bitset = BitSet<>(m_vertices.size()); m_bottom_visible_bitset = BitSet<>(m_vertices.size()); + }; + try { + update_shell_bitset(); + } + catch (const std::bad_alloc&) { + // out of memory on a huge print: take everything for shell, which leaves out only the hidden infill + fallback(); + } + catch (const std::system_error&) { + // a worker thread could not be launched + fallback(); } } #endif // ENABLE_OPENGL_ES