From 48875d8d6ccabd344d95be15f8537b0c8c8f7f18 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 27 May 2015 16:16:07 +0300 Subject: [PATCH] Notify glyph parsing errors Emit a signal when the glyphs are not parsed correctly. --- src/mbgl/text/glyph_pbf.cpp | 4 ++-- src/mbgl/text/glyph_pbf.hpp | 5 +++++ src/mbgl/text/glyph_store.cpp | 10 ++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp index c0642af29..899df39d3 100644 --- a/src/mbgl/text/glyph_pbf.cpp +++ b/src/mbgl/text/glyph_pbf.cpp @@ -23,14 +23,14 @@ GlyphPBF::GlyphPBF(const std::string& glyphURL, const GlyphLoadingFailedCallback& failureCallback) : parsed(false), env(env_) { // Load the glyph set URL - std::string url = util::replaceTokens(glyphURL, [&](const std::string &name) -> std::string { + url = util::replaceTokens(glyphURL, [&](const std::string &name) -> std::string { if (name == "fontstack") return util::percentEncode(fontStack); if (name == "range") return util::toString(glyphRange.first) + "-" + util::toString(glyphRange.second); return ""; }); // The prepare call jumps back to the main thread. - req = env.request({ Resource::Kind::Glyphs, url }, [&, url, successCallback, failureCallback](const Response &res) { + req = env.request({ Resource::Kind::Glyphs, url }, [&, successCallback, failureCallback](const Response &res) { req = nullptr; if (res.status != Response::Successful) { diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp index cb36dde03..bb6fa83ae 100644 --- a/src/mbgl/text/glyph_pbf.hpp +++ b/src/mbgl/text/glyph_pbf.hpp @@ -29,6 +29,10 @@ public: void parse(FontStack &stack); bool isParsed() const; + std::string getURL() const { + return url; + } + private: GlyphPBF(const GlyphPBF &) = delete; GlyphPBF(GlyphPBF &&) = delete; @@ -36,6 +40,7 @@ private: GlyphPBF &operator=(GlyphPBF &&) = delete; std::string data; + std::string url; std::atomic parsed; Environment& env; diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp index ea451e278..9520b63c0 100644 --- a/src/mbgl/text/glyph_store.cpp +++ b/src/mbgl/text/glyph_store.cpp @@ -34,8 +34,14 @@ bool GlyphStore::requestGlyphRangesIfNeeded(const std::string& fontStackName, auto successCallback = [this, fontStackName](GlyphPBF* glyph) { auto fontStack = createFontStack(fontStackName); - glyph->parse(**fontStack); - asyncEmitGlyphRangeLoaded->send(); + try { + glyph->parse(**fontStack); + asyncEmitGlyphRangeLoaded->send(); + } catch (const std::exception&) { + std::lock_guard lock(errorMessageMutex); + errorMessage = "Failed to parse [" + glyph->getURL() + "]"; + asyncEmitGlyphRangeLoadedingFailed->send(); + } }; auto failureCallback = [this](const std::string& message) {