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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user