From ec7c74d04c6da2f2cba0977ccf05aa9dcf7021ce Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Mon, 7 Sep 2015 09:26:36 -0700 Subject: [PATCH] Ref count elemental. --- src/xenia/ui/window.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/xenia/ui/window.cc b/src/xenia/ui/window.cc index 4182c7607..c1f6277ed 100644 --- a/src/xenia/ui/window.cc +++ b/src/xenia/ui/window.cc @@ -38,6 +38,9 @@ constexpr double kDoubleClickDistance = 5; constexpr int32_t kMouseWheelDetent = 120; +// Ref count of elemental initializations. +int32_t elemental_initialization_count_ = 0; + class RootElement : public el::Element { public: explicit RootElement(Window* owner) : owner_(owner) {} @@ -58,11 +61,9 @@ Window::~Window() { bool Window::InitializeElemental(Loop* loop, el::graphics::Renderer* renderer) { GraphicsContextLock context_lock(context_.get()); - static bool has_initialized = false; - if (has_initialized) { + if (++elemental_initialization_count_ > 1) { return true; } - has_initialized = true; // Need to pass off the Loop we want Elemental to use. // TODO(benvanik): give the callback to elemental instead. @@ -156,7 +157,9 @@ void Window::OnClose() { } void Window::OnDestroy() { - el::Shutdown(); + if (--elemental_initialization_count_ == 0) { + el::Shutdown(); + } // Context must go last. root_element_.reset();