[core] send signal to RenderCustomLayer when gl context has been lost

- Prevents cleaning up of GL resources that no longer exist, resulting in a crash
This commit is contained in:
Ivo van Dongen
2017-09-15 18:03:04 +03:00
committed by Ivo van Dongen
parent 67285f3a95
commit bda6ed26c6
6 changed files with 29 additions and 1 deletions

View File

@@ -28,6 +28,8 @@ public:
const optional<std::string> programCacheDir = {});
~Renderer();
void markContextLost();
void setObserver(RendererObserver*);
void render(const UpdateParameters&);

View File

@@ -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);
}
}

View File

@@ -19,8 +19,13 @@ public:
const style::CustomLayer::Impl& impl() const;
void markContextDestroyed() {
contextDestroyed = true;
};
private:
bool initialized = false;
bool contextDestroyed = false;
};
template <>

View File

@@ -20,6 +20,10 @@ Renderer::~Renderer() {
impl.reset();
}
void Renderer::markContextLost() {
impl->markContextLost();
}
void Renderer::setObserver(RendererObserver* observer) {
impl->setObserver(observer);
}

View File

@@ -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_) {

View File

@@ -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