Ref count elemental.
This commit is contained in:
parent
539f69f368
commit
ec7c74d04c
|
@ -38,6 +38,9 @@ constexpr double kDoubleClickDistance = 5;
|
||||||
|
|
||||||
constexpr int32_t kMouseWheelDetent = 120;
|
constexpr int32_t kMouseWheelDetent = 120;
|
||||||
|
|
||||||
|
// Ref count of elemental initializations.
|
||||||
|
int32_t elemental_initialization_count_ = 0;
|
||||||
|
|
||||||
class RootElement : public el::Element {
|
class RootElement : public el::Element {
|
||||||
public:
|
public:
|
||||||
explicit RootElement(Window* owner) : owner_(owner) {}
|
explicit RootElement(Window* owner) : owner_(owner) {}
|
||||||
|
@ -58,11 +61,9 @@ Window::~Window() {
|
||||||
bool Window::InitializeElemental(Loop* loop, el::graphics::Renderer* renderer) {
|
bool Window::InitializeElemental(Loop* loop, el::graphics::Renderer* renderer) {
|
||||||
GraphicsContextLock context_lock(context_.get());
|
GraphicsContextLock context_lock(context_.get());
|
||||||
|
|
||||||
static bool has_initialized = false;
|
if (++elemental_initialization_count_ > 1) {
|
||||||
if (has_initialized) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
has_initialized = true;
|
|
||||||
|
|
||||||
// Need to pass off the Loop we want Elemental to use.
|
// Need to pass off the Loop we want Elemental to use.
|
||||||
// TODO(benvanik): give the callback to elemental instead.
|
// TODO(benvanik): give the callback to elemental instead.
|
||||||
|
@ -156,7 +157,9 @@ void Window::OnClose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OnDestroy() {
|
void Window::OnDestroy() {
|
||||||
el::Shutdown();
|
if (--elemental_initialization_count_ == 0) {
|
||||||
|
el::Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
// Context must go last.
|
// Context must go last.
|
||||||
root_element_.reset();
|
root_element_.reset();
|
||||||
|
|
Loading…
Reference in New Issue