summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-07-13 15:35:02 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-07-19 17:34:07 +0200
commit733661948c004dad70e634aa9f2b41402e460a6e (patch)
tree0f4cc6e0ad280eafff1fc757b419ce49b28ce6b2 /src
parent2d147470a5f982afb0c1a63ff632497f85ea85bf (diff)
downloadqtlocation-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.cpp35
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();
}