fix crash bug for styles that have no glyph url specified

This commit is contained in:
Konstantin Käfer
2014-08-06 18:33:21 +02:00
parent 915e89bee8
commit 9dc48b773f
3 changed files with 15 additions and 14 deletions

View File

@@ -62,13 +62,15 @@ private:
// Manages Glyphrange PBF loading.
class GlyphStore {
public:
GlyphStore(const std::string &glyphURL);
GlyphStore();
// Block until all specified GlyphRanges of the specified font stack are loaded.
void waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges);
FontStack &getFontStack(const std::string &fontStack);
void setURL(const std::string &url);
private:
// Loads an individual glyph range from the font stack and adds it to rangeSets
std::shared_future<GlyphPBF &> loadGlyphRange(const std::string &fontStack, std::map<GlyphRange, std::unique_ptr<GlyphPBF>> &rangeSets, GlyphRange range);
@@ -76,7 +78,7 @@ private:
FontStack &createFontStack(const std::string &fontStack);
public:
const std::string glyphURL;
std::string glyphURL;
private:
std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges;

View File

@@ -33,6 +33,7 @@ Map::Map(View& view)
transform(view),
style(std::make_shared<Style>()),
glyphAtlas(std::make_shared<GlyphAtlas>(1024, 1024)),
glyphStore(std::make_shared<GlyphStore>()),
spriteAtlas(std::make_shared<SpriteAtlas>(512, 512)),
texturepool(std::make_shared<Texturepool>()),
painter(*this),
@@ -187,6 +188,7 @@ void Map::setStyleJSON(std::string newStyleJSON) {
styleJSON.swap(newStyleJSON);
sprite.reset();
style->loadJSON((const uint8_t *)styleJSON.c_str());
glyphStore->setURL(style->glyph_url);
update();
}
@@ -514,16 +516,6 @@ void Map::prepare() {
bool dimensionsChanged = oldState.getFramebufferWidth() != state.getFramebufferWidth() ||
oldState.getFramebufferHeight() != state.getFramebufferHeight();
// Create a new glyph store object in case the glyph URL changed.
// TODO: Move this to a less frequently called place; we only need to do this when the
// stylesheet changes.
if (glyphStore && glyphStore->glyphURL != style->glyph_url) {
glyphStore.reset();
}
if (!glyphStore && style->glyph_url.size()) {
glyphStore = std::make_shared<GlyphStore>(style->glyph_url);
}
if (pixelRatioChanged || dimensionsChanged) {
painter.clearFramebuffers();
}

View File

@@ -226,12 +226,19 @@ void GlyphPBF::parse(FontStack &stack) {
data.clear();
}
GlyphStore::GlyphStore(const std::string &glyphURL)
: glyphURL(glyphURL) {}
GlyphStore::GlyphStore() {}
void GlyphStore::setURL(const std::string &url) {
glyphURL = url;
}
void GlyphStore::waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges) {
// We are implementing a blocking wait with futures: Every GlyphSet has a future that we are
// waiting for until it is loaded.
if (glyphRanges.empty()) {
return;
}
FontStack *stack = nullptr;