Improved error handling

This commit is contained in:
Martin Tůma 2018-11-26 22:37:16 +01:00
parent 6f5bedb82b
commit ccfcc370d6

View File

@ -61,9 +61,13 @@ bool Sprites::load(const QString &jsonFile, const QString &imageFile)
for (QJsonObject::const_iterator it = json.constBegin(); for (QJsonObject::const_iterator it = json.constBegin();
it != json.constEnd(); it++) { it != json.constEnd(); it++) {
QJsonValue val(*it); QJsonValue val(*it);
if (val.isObject()) if (val.isObject()) {
_sprites.insert(it.key(), Sprite(val.toObject())); Sprite s(val.toObject());
else if (s.rect().isValid())
_sprites.insert(it.key(), s);
else
qWarning() << it.key() << ": invalid sprite definition";
} else
qWarning() << it.key() << ": invalid sprite definition"; qWarning() << it.key() << ": invalid sprite definition";
} }
@ -82,10 +86,8 @@ QImage Sprites::icon(const QString &name) const
if (it == _sprites.constEnd()) if (it == _sprites.constEnd())
return QImage(); return QImage();
if (!img.rect().contains(it->rect())) { if (!img.rect().contains(it->rect()))
qWarning() << it->rect() << ": invalid sprite rect";
return QImage(); return QImage();
}
return img.copy(it->rect()); return img.copy(it->rect());
} }