From d3c7f3b73d7eab4c198356f0175872d426a40ea2 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 15 Jan 2016 18:18:24 -1000 Subject: [PATCH] Destruction order bug fix --- specter/include/Specter/Menu.hpp | 5 +++-- specter/lib/Menu.cpp | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/specter/include/Specter/Menu.hpp b/specter/include/Specter/Menu.hpp index c9f6b6d67..8622843bb 100644 --- a/specter/include/Specter/Menu.hpp +++ b/specter/include/Specter/Menu.hpp @@ -67,8 +67,8 @@ class Menu : public View Menu& m_menu; std::unique_ptr m_textView; size_t m_idx; - IMenuNode& m_node; - ItemView(ViewResources& res, Menu& menu, const std::string& text, size_t idx, IMenuNode& node); + IMenuNode* m_node; + ItemView(ViewResources& res, Menu& menu, const std::string& text, size_t idx, IMenuNode* node); void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); @@ -79,6 +79,7 @@ class Menu : public View void draw(boo::IGraphicsCommandQueue* gfxQ); }; std::vector>> m_items; + IMenuNode* m_deferredActivation = nullptr; Menu(ViewResources& res, View& parentView, IMenuNode* rootNode, IMenuNode* thisNode); diff --git a/specter/lib/Menu.cpp b/specter/lib/Menu.cpp index a67a7d206..6169bb368 100644 --- a/specter/lib/Menu.cpp +++ b/specter/lib/Menu.cpp @@ -56,7 +56,7 @@ void Menu::reset(IMenuNode* rootNode) if (nodeText) { - item.m_view.reset(new ItemView(res, *this, *nodeText, i, *node)); + item.m_view.reset(new ItemView(res, *this, *nodeText, i, node)); m_cWidth = std::max(m_cWidth, int(item.m_view->m_textView->nominalWidth() + 10*pf)); } @@ -88,7 +88,7 @@ Menu::ContentView::ContentView(ViewResources& res, Menu& menu) m_hlVerts[3].m_color = res.themeData().button2Hover(); } -Menu::ItemView::ItemView(ViewResources& res, Menu& menu, const std::string& text, size_t idx, IMenuNode& node) +Menu::ItemView::ItemView(ViewResources& res, Menu& menu, const std::string& text, size_t idx, IMenuNode* node) : View(res, menu), m_menu(menu), m_idx(idx), m_node(node) { commitResources(res); @@ -157,6 +157,12 @@ void Menu::ItemView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton void Menu::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) { m_scroll.mouseUp(coord, button, mod); + if (m_deferredActivation) + { + IMenuNode* node = m_deferredActivation; + m_deferredActivation = nullptr; + node->activated(coord); + } } void Menu::ContentView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) @@ -168,7 +174,7 @@ void Menu::ContentView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButto void Menu::ItemView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) { if (m_menu.m_content->m_highlightedItem == m_idx) - m_node.activated(coord); + m_menu.m_deferredActivation = m_node; } void Menu::mouseMove(const boo::SWindowCoord& coord)