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.
This commit is contained in:
Thiago Marcos P. Santos
2015-05-29 12:13:24 +03:00
parent 9b36b48268
commit 29b8b44b77
3 changed files with 12 additions and 0 deletions

View File

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

View File

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

View File

@@ -59,6 +59,10 @@ public:
void setDefaultTransitionDuration(Duration);
bool hasTransitions() const;
std::exception_ptr getLastError() const {
return lastError;
}
std::unique_ptr<GlyphStore> glyphStore;
std::unique_ptr<GlyphAtlas> glyphAtlas;
util::ptr<Sprite> sprite;
@@ -90,6 +94,8 @@ private:
Observer* observer = nullptr;
std::exception_ptr lastError;
std::string spriteURL;
PropertyTransition defaultTransition;
std::unique_ptr<uv::rwlock> mtx;