Do not report isLoaded() if loading failed

This commit is contained in:
Thiago Marcos P. Santos
2015-07-09 16:28:26 +03:00
parent 0ee9f21c56
commit b33d5d8a95
2 changed files with 5 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ Sprite::Sprite(const std::string& baseUrl, float pixelRatio_)
: pixelRatio(pixelRatio_ > 1 ? 2 : 1) {
if (baseUrl.empty()) {
// Treat a non-existent sprite as a successfully loaded empty sprite.
loaded = true;
return;
}
@@ -95,6 +96,7 @@ void Sprite::emitSpriteLoadedIfComplete() {
auto result = parseSprite(data->image, data->json);
if (result.is<Sprites>()) {
loaded = true;
observer->onSpriteLoaded(result.get<Sprites>());
} else {
emitSpriteLoadingFailed(result.get<std::string>());

View File

@@ -36,7 +36,7 @@ public:
~Sprite();
inline bool isLoaded() const {
return loader == nullptr;
return loaded;
}
const float pixelRatio;
@@ -50,6 +50,8 @@ private:
struct Loader;
std::unique_ptr<Loader> loader;
bool loaded = false;
Observer* observer = nullptr;
};