summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-03-12 15:25:47 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-03-12 15:27:56 +0100
commit74ef8840ce93f8ceb204bbe787f00a460ff51229 (patch)
treee5fc81977128090b5e5f841bdd6b7c04a8ada43f /src
parent2b6afe6a549284a862d0231653d2183d57a5b496 (diff)
downloadqtlocation-mapboxgl-74ef8840ce93f8ceb204bbe787f00a460ff51229.tar.gz
tolerate missing sprites
Do not try to fulfil the promise twice in case both requests to the sprite JSON and image fail. this will crash the program. Instead, we always continue with the promise, instead of throwing an exception. This allows the program to continue parsing tiles, but without an image sprite available. This means the map will render, but without the sprite images
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/sprite.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/mbgl/map/sprite.cpp b/src/mbgl/map/sprite.cpp
index 4be92ff73f..114e8f45f5 100644
--- a/src/mbgl/map/sprite.cpp
+++ b/src/mbgl/map/sprite.cpp
@@ -54,7 +54,6 @@ Sprite::operator bool() const {
// The reason this isn't part of the constructor is that calling shared_from_this() in
// the constructor fails.
void Sprite::load(Environment &env) {
-
if (!valid) {
// Treat a non-existent sprite as a successfully loaded empty sprite.
loadedImage = true;
@@ -69,22 +68,22 @@ void Sprite::load(Environment &env) {
if (res.status == Response::Successful) {
sprite->body = res.data;
sprite->parseJSON();
- sprite->complete();
} else {
Log::Warning(Event::Sprite, "Failed to load sprite info: %s", res.message.c_str());
- sprite->promise.set_exception(std::make_exception_ptr(std::runtime_error(res.message)));
}
+ sprite->loadedJSON = true;
+ sprite->complete();
});
env.request({ Resource::Kind::Image, spriteURL }, [sprite](const Response &res) {
if (res.status == Response::Successful) {
sprite->image = res.data;
sprite->parseImage();
- sprite->complete();
} else {
Log::Warning(Event::Sprite, "Failed to load sprite image: %s", res.message.c_str());
- sprite->promise.set_exception(std::make_exception_ptr(std::runtime_error(res.message)));
}
+ sprite->loadedImage = true;
+ sprite->complete();
});
}
@@ -104,7 +103,6 @@ void Sprite::parseImage() {
raster.reset();
}
image.clear();
- loadedImage = true;
}
void Sprite::parseJSON() {
@@ -139,8 +137,6 @@ void Sprite::parseJSON() {
} else {
Log::Warning(Event::Sprite, "sprite JSON root is not an object");
}
-
- loadedJSON = true;
}
const SpritePosition &Sprite::getSpritePosition(const std::string& name) const {