diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-07-13 15:35:02 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-07-19 17:34:07 +0200 |
commit | 733661948c004dad70e634aa9f2b41402e460a6e (patch) | |
tree | 0f4cc6e0ad280eafff1fc757b419ce49b28ce6b2 /src | |
parent | 2d147470a5f982afb0c1a63ff632497f85ea85bf (diff) | |
download | qtlocation-mapboxgl-733661948c004dad70e634aa9f2b41402e460a6e.tar.gz |
[core] BackendScope prevent double (de-)activation
- Guards against duplicate activations by checking wether the backend of the prior scope is the same as the current ones
- Makes sure that only the most outer backend scope deactivates by tracking activation state
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/backend_scope.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/mbgl/map/backend_scope.cpp b/src/mbgl/map/backend_scope.cpp index 824ad4498b..dac90346d7 100644 --- a/src/mbgl/map/backend_scope.cpp +++ b/src/mbgl/map/backend_scope.cpp @@ -16,30 +16,49 @@ BackendScope::BackendScope(Backend& backend_, ScopeType scopeType_) if (priorScope) { assert(priorScope->nextScope == nullptr); priorScope->nextScope = this; + priorScope->deactivate(); } - if (scopeType == ScopeType::Explicit) { - backend.activate(); - } + + activate(); currentScope.set(this); } BackendScope::~BackendScope() { assert(nextScope == nullptr); + deactivate(); + if (priorScope) { - priorScope->backend.activate(); + priorScope->activate(); currentScope.set(priorScope); assert(priorScope->nextScope == this); priorScope->nextScope = nullptr; } else { - if (scopeType == ScopeType::Explicit) { - backend.deactivate(); - } - currentScope.set(nullptr); } } +void BackendScope::activate() { + if (scopeType == ScopeType::Explicit && + !(priorScope && this->backend == priorScope->backend) && + !(nextScope && this->backend == nextScope->backend)) { + // Only activate when set to Explicit and + // only once per RenderBackend + backend.activate(); + activated = true; + } +} + +void BackendScope::deactivate() { + if (activated && + !(nextScope && this->backend == nextScope->backend)) { + // Only deactivate when set to Explicit and + // only once per RenderBackend + backend.deactivate(); + activated = false; + } +} + bool BackendScope::exists() { return currentScope.get(); } |