diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-02-27 18:33:16 +0100 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-23 14:50:11 -0700 |
commit | 8e5214144ec4f3a4fb40b7a7e4d8f09fd10dbb78 (patch) | |
tree | cf79b67b4af670438cbc79a524be82e88da83904 /src | |
parent | d7227e13a7a87cf50a4c8c1f0615fc565f5a2679 (diff) | |
download | qtlocation-mapboxgl-8e5214144ec4f3a4fb40b7a7e4d8f09fd10dbb78.tar.gz |
[core] Ensure that a BackendScope exists when doing GL calls
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/backend.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/backend_scope.cpp | 19 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 3 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/mbgl/map/backend.cpp b/src/mbgl/map/backend.cpp index 2a171cdb76..a1a2f8f3a8 100644 --- a/src/mbgl/map/backend.cpp +++ b/src/mbgl/map/backend.cpp @@ -1,4 +1,5 @@ #include <mbgl/map/backend.hpp> +#include <mbgl/map/backend_scope.hpp> #include <mbgl/gl/context.hpp> #include <cassert> @@ -9,6 +10,7 @@ Backend::Backend() : context(std::make_unique<gl::Context>()) { } gl::Context& Backend::getContext() { + assert(BackendScope::exists()); return *context; } diff --git a/src/mbgl/map/backend_scope.cpp b/src/mbgl/map/backend_scope.cpp index 98775ceadb..824ad4498b 100644 --- a/src/mbgl/map/backend_scope.cpp +++ b/src/mbgl/map/backend_scope.cpp @@ -8,15 +8,19 @@ namespace mbgl { static util::ThreadLocal<BackendScope> currentScope; -BackendScope::BackendScope(Backend& backend_) +BackendScope::BackendScope(Backend& backend_, ScopeType scopeType_) : priorScope(currentScope.get()), nextScope(nullptr), - backend(backend_) { + backend(backend_), + scopeType(scopeType_) { if (priorScope) { assert(priorScope->nextScope == nullptr); priorScope->nextScope = this; } - backend.activate(); + if (scopeType == ScopeType::Explicit) { + backend.activate(); + } + currentScope.set(this); } @@ -28,9 +32,16 @@ BackendScope::~BackendScope() { assert(priorScope->nextScope == this); priorScope->nextScope = nullptr; } else { - backend.deactivate(); + if (scopeType == ScopeType::Explicit) { + backend.deactivate(); + } + currentScope.set(nullptr); } } +bool BackendScope::exists() { + return currentScope.get(); +} + } // namespace mbgl diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 4c787eb660..a883a69282 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -267,8 +267,9 @@ void Map::Impl::render(View& view) { updateFlags = Update::Nothing; + gl::Context& context = backend.getContext(); if (!painter) { - painter = std::make_unique<Painter>(backend.getContext(), transform.getState(), pixelRatio, programCacheDir); + painter = std::make_unique<Painter>(context, transform.getState(), pixelRatio, programCacheDir); } if (mode == MapMode::Continuous) { |