From 6e8bb8adc62a480b1fe1d9fd96b19d3637d9a3f1 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 29 Nov 2021 03:37:22 -0600 Subject: [PATCH] [nostalgia/studio] Fix closing last tab --- src/nostalgia/studio/studioapp.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/nostalgia/studio/studioapp.cpp b/src/nostalgia/studio/studioapp.cpp index 08406eeb..12f33dc8 100644 --- a/src/nostalgia/studio/studioapp.cpp +++ b/src/nostalgia/studio/studioapp.cpp @@ -140,7 +140,8 @@ void StudioUI::drawTabs() noexcept { ImGui::Begin("TabWindow##MainWindow", nullptr, windowFlags); constexpr auto tabBarFlags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_TabListPopupButton; if (ImGui::BeginTabBar("TabBar##TabWindow##MainWindow", tabBarFlags)) { - for (auto &e : m_editors) { + for (auto it = m_editors.begin(); it != m_editors.end(); ) { + auto const &e = *it; bool open = true; if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open)) { e->draw(m_ctx); @@ -149,10 +150,14 @@ void StudioUI::drawTabs() noexcept { if (!open) { e->close(); try { - oxThrowError(m_editors.erase(e)); - } catch (const std::exception &e) { - oxErrf("Editor tab deletion failed: {}", e.what()); + oxThrowError(m_editors.erase(it).moveTo(&it)); + } catch (const ox::Exception &ex) { + oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.file, ex.line); + } catch (const std::exception &ex) { + oxErrf("Editor tab deletion failed: {}\n", ex.what()); } + } else { + ++it; } } ImGui::EndTabBar(); @@ -173,10 +178,10 @@ void StudioUI::loadModule(studio::Module *module) noexcept { } void StudioUI::loadModules() noexcept { - //for (auto &moduleMaker : BuiltinModules) { - // const auto module = moduleMaker(); - // loadModule(module.get()); - //} + for (auto &moduleMaker : BuiltinModules) { + const auto module = moduleMaker(); + loadModule(module.get()); + } } ox::Error StudioUI::openProject(const ox::String &path) noexcept {