From 29b8b44b7767312095e9489a97ba9eea3f1797af Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 29 May 2015 12:13:24 +0300 Subject: [PATCH] Fix race condition on error notification We start loading the resources at the moment we set the style, but we set the callback for error notification at renderStill(), which happen afterwards. If some error occurs in this short window, it was never being notified. Now we save the last error and we check after we set the callback. --- src/mbgl/map/map_context.cpp | 5 +++++ src/mbgl/style/style.cpp | 1 + src/mbgl/style/style.hpp | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index a834f5065..47a6b3e4b 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -176,6 +176,11 @@ void MapContext::renderStill(StillImageCallback fn) { throw util::Exception("Map is currently rendering an image"); } + if (style->getLastError()) { + fn(style->getLastError(), nullptr); + return; + } + callback = fn; triggerUpdate(Update::RenderStill); } diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 8999af3c7..30798e08e 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -203,6 +203,7 @@ void Style::emitResourceLoadingFailed(std::exception_ptr error) { try { if (error) { + lastError = error; std::rethrow_exception(error); } } catch(const std::exception& e) { diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index c70f019c4..a22067cb1 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -59,6 +59,10 @@ public: void setDefaultTransitionDuration(Duration); bool hasTransitions() const; + std::exception_ptr getLastError() const { + return lastError; + } + std::unique_ptr glyphStore; std::unique_ptr glyphAtlas; util::ptr sprite; @@ -90,6 +94,8 @@ private: Observer* observer = nullptr; + std::exception_ptr lastError; + std::string spriteURL; PropertyTransition defaultTransition; std::unique_ptr mtx;