summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-08-24 17:38:06 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-08-24 20:02:31 +0300
commitc98f4f476bd590bdfd78409d428459e40347302a (patch)
tree6c4bc14970ba0bf199e36156e3bc529a6d054a61 /src/mbgl/style
parent646528bc53c37950b556be825de1ba9fa5303be3 (diff)
downloadqtlocation-mapboxgl-c98f4f476bd590bdfd78409d428459e40347302a.tar.gz
[core] Emit MapChangeDidFailLoadingMap when the style cannot be loaded or parsed
Currently this signal is never emitted, which can cause the Still mode to starve in case of an invalid style or failed request.
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/observer.hpp1
-rw-r--r--src/mbgl/style/parser.cpp15
-rw-r--r--src/mbgl/style/parser.hpp5
-rw-r--r--src/mbgl/style/style.cpp10
4 files changed, 24 insertions, 7 deletions
diff --git a/src/mbgl/style/observer.hpp b/src/mbgl/style/observer.hpp
index 2c48114669..c4d31ae249 100644
--- a/src/mbgl/style/observer.hpp
+++ b/src/mbgl/style/observer.hpp
@@ -18,6 +18,7 @@ public:
* and `onNeedsRepaint` will be called.
*/
void onNeedsRepaint() override {}
+ virtual void onStyleError() {}
virtual void onResourceError(std::exception_ptr) {}
};
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index bc05b5484a..e53fac2667 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -14,24 +14,27 @@
#include <algorithm>
#include <set>
+#include <sstream>
namespace mbgl {
namespace style {
Parser::~Parser() = default;
-void Parser::parse(const std::string& json) {
+StyleParseResult Parser::parse(const std::string& json) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
document.Parse<0>(json.c_str());
if (document.HasParseError()) {
- Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", document.GetErrorOffset(), rapidjson::GetParseError_En(document.GetParseError()));
- return;
+ std::stringstream message;
+ message << document.GetErrorOffset() << " - "
+ << rapidjson::GetParseError_En(document.GetParseError());
+
+ return std::make_exception_ptr(std::runtime_error(message.str()));
}
if (!document.IsObject()) {
- Log::Error(Event::ParseStyle, "Style JSON must be an object");
- return;
+ return std::make_exception_ptr(std::runtime_error("style must be an object"));
}
if (document.HasMember("version")) {
@@ -100,6 +103,8 @@ void Parser::parse(const std::string& json) {
glyphURL = { glyphs.GetString(), glyphs.GetStringLength() };
}
}
+
+ return nullptr;
}
void Parser::parseSources(const JSValue& value) {
diff --git a/src/mbgl/style/parser.hpp b/src/mbgl/style/parser.hpp
index a6a71ed817..a05a0b316a 100644
--- a/src/mbgl/style/parser.hpp
+++ b/src/mbgl/style/parser.hpp
@@ -9,6 +9,7 @@
#include <vector>
#include <memory>
+#include <stdexcept>
#include <string>
#include <unordered_map>
#include <forward_list>
@@ -16,11 +17,13 @@
namespace mbgl {
namespace style {
+using StyleParseResult = std::exception_ptr;
+
class Parser {
public:
~Parser();
- void parse(const std::string&);
+ StyleParseResult parse(const std::string&);
std::string spriteURL;
std::string glyphURL;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 1cf64002fb..e04384a96e 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -90,7 +90,15 @@ void Style::setJSON(const std::string& json) {
classes.clear();
Parser parser;
- parser.parse(json);
+ auto error = parser.parse(json);
+
+ if (error) {
+ Log::Error(Event::ParseStyle, "Failed to parse style: %s", util::toString(error).c_str());
+ observer->onStyleError();
+ observer->onResourceError(error);
+
+ return;
+ }
for (auto& source : parser.sources) {
addSource(std::move(source));