summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/renderer/layers/render_custom_layer.cpp2
-rw-r--r--src/mbgl/renderer/layers/render_custom_layer.hpp5
-rw-r--r--src/mbgl/renderer/renderer.cpp4
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp11
-rw-r--r--src/mbgl/renderer/renderer_impl.hpp6
5 files changed, 27 insertions, 1 deletions
diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp
index ae0c4b026b..3d19f5ef46 100644
--- a/src/mbgl/renderer/layers/render_custom_layer.cpp
+++ b/src/mbgl/renderer/layers/render_custom_layer.cpp
@@ -16,7 +16,7 @@ RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl)
RenderCustomLayer::~RenderCustomLayer() {
assert(BackendScope::exists());
- if (initialized && impl().deinitializeFn) {
+ if (initialized && !contextDestroyed && impl().deinitializeFn) {
impl().deinitializeFn(impl().context);
}
}
diff --git a/src/mbgl/renderer/layers/render_custom_layer.hpp b/src/mbgl/renderer/layers/render_custom_layer.hpp
index d8e9d93811..32ed9da8da 100644
--- a/src/mbgl/renderer/layers/render_custom_layer.hpp
+++ b/src/mbgl/renderer/layers/render_custom_layer.hpp
@@ -19,8 +19,13 @@ public:
const style::CustomLayer::Impl& impl() const;
+ void markContextDestroyed() {
+ contextDestroyed = true;
+ };
+
private:
bool initialized = false;
+ bool contextDestroyed = false;
};
template <>
diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp
index a106d6c5fa..e915f5e146 100644
--- a/src/mbgl/renderer/renderer.cpp
+++ b/src/mbgl/renderer/renderer.cpp
@@ -20,6 +20,10 @@ Renderer::~Renderer() {
impl.reset();
}
+void Renderer::markContextLost() {
+ impl->markContextLost();
+}
+
void Renderer::setObserver(RendererObserver* observer) {
impl->setObserver(observer);
}
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index c45295b693..1a828b80a3 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -62,6 +62,17 @@ Renderer::Impl::Impl(RendererBackend& backend_,
Renderer::Impl::~Impl() {
assert(BackendScope::exists());
+
+ if (contextLost) {
+ // Signal all RenderCustomLayers that the context was lost
+ // before cleaning up
+ for (const auto& entry : renderLayers) {
+ RenderLayer& layer = *entry.second;
+ if (layer.is<RenderCustomLayer>()) {
+ layer.as<RenderCustomLayer>()->markContextDestroyed();
+ }
+ }
+ }
};
void Renderer::Impl::setObserver(RendererObserver* observer_) {
diff --git a/src/mbgl/renderer/renderer_impl.hpp b/src/mbgl/renderer/renderer_impl.hpp
index 8bdb472442..30e7f70722 100644
--- a/src/mbgl/renderer/renderer_impl.hpp
+++ b/src/mbgl/renderer/renderer_impl.hpp
@@ -39,6 +39,10 @@ public:
const optional<std::string> programCacheDir);
~Impl() final;
+ void markContextLost() {
+ contextLost = true;
+ };
+
void setObserver(RendererObserver*);
void render(const UpdateParameters&);
@@ -100,6 +104,8 @@ private:
std::unordered_map<std::string, std::unique_ptr<RenderSource>> renderSources;
std::unordered_map<std::string, std::unique_ptr<RenderLayer>> renderLayers;
RenderLight renderLight;
+
+ bool contextLost = false;
};
} // namespace mbgl