summaryrefslogtreecommitdiff
path: root/src/mbgl/sprite/sprite_atlas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/sprite/sprite_atlas.cpp')
-rw-r--r--src/mbgl/sprite/sprite_atlas.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp
index ae71f18f03..6ebebb9507 100644
--- a/src/mbgl/sprite/sprite_atlas.cpp
+++ b/src/mbgl/sprite/sprite_atlas.cpp
@@ -47,17 +47,17 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(const size_t pixel_width
return rect;
}
-SpriteAtlasElement SpriteAtlas::getImage(const std::string& name, const bool wrap) {
+mapbox::util::optional<SpriteAtlasElement> SpriteAtlas::getImage(const std::string& name, const bool wrap) {
std::lock_guard<std::recursive_mutex> lock(mtx);
auto rect_it = images.find({ name, wrap });
if (rect_it != images.end()) {
- return { rect_it->second.pos, rect_it->second.texture };
+ return SpriteAtlasElement { rect_it->second.pos, rect_it->second.texture };
}
auto sprite = store.getSprite(name);
if (!sprite) {
- return { Rect<dimension> { 0, 0, 0, 0 }, nullptr };
+ return {};
}
Rect<dimension> rect = allocateImage(sprite->width, sprite->height);
@@ -65,19 +65,24 @@ SpriteAtlasElement SpriteAtlas::getImage(const std::string& name, const bool wra
if (debug::spriteWarnings) {
Log::Warning(Event::Sprite, "sprite atlas bitmap overflow");
}
- return { Rect<dimension> { 0, 0, 0, 0 }, nullptr };
+ return {};
}
const Holder& holder = images.emplace(Key{ name, wrap }, Holder{ sprite, rect }).first->second;
copy(holder, wrap);
- return { rect, sprite };
+ return SpriteAtlasElement { rect, sprite };
}
-SpriteAtlasPosition SpriteAtlas::getPosition(const std::string& name, bool repeating) {
+mapbox::util::optional<SpriteAtlasPosition> SpriteAtlas::getPosition(const std::string& name, bool repeating) {
std::lock_guard<std::recursive_mutex> lock(mtx);
- auto rect = getImage(name, repeating).pos;
+ auto img = getImage(name, repeating);
+ if (!img) {
+ return {};
+ }
+
+ auto rect = (*img).pos;
if (repeating) {
// When the image is repeating, get the correct position of the image, rather than the
// one rounded up to 4 pixels.