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-18 10:45:12 +0200 |
commit | 9ebf727f56819f259a7a0771b1ed58b14c3adea3 (patch) | |
tree | 0fa580307dda6cbc63674c5b8b351455fe94a318 /src | |
parent | a5a0558bde5d67617b6f305179063cd4e0ac329e (diff) | |
download | qtlocation-mapboxgl-9ebf727f56819f259a7a0771b1ed58b14c3adea3.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/renderer/backend_scope.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/mbgl/renderer/backend_scope.cpp b/src/mbgl/renderer/backend_scope.cpp index 5d57421c48..fafeaabb39 100644 --- a/src/mbgl/renderer/backend_scope.cpp +++ b/src/mbgl/renderer/backend_scope.cpp @@ -16,30 +16,49 @@ BackendScope::BackendScope(RendererBackend& 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(); } |