diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2019-04-08 18:11:44 +0300 |
---|---|---|
committer | Rebecca Worledge <rebecca.worledge@theqtcompany.com> | 2019-04-09 02:56:36 +0000 |
commit | a6c677ca70462dda0e7bdf3723093bb7ae5d82ff (patch) | |
tree | e6ee890293ff2314a74bb79b1494d3b68da8b11b | |
parent | fa0b3f9bf148ecefb2ddef124ac753937cc643c4 (diff) |
LottieAnimation: fix error reporting for JSON parser related issues
* add some verbosity
* statusChanged() signal was never fired for parse errors
Change-Id: Idc2a43140eaebeb8ed1d822075f39e742be0e404
Reviewed-by: Rebecca Worledge <rebecca.worledge@theqtcompany.com>
-rw-r--r-- | src/imports/lottieanimation.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/imports/lottieanimation.cpp b/src/imports/lottieanimation.cpp index dddf88a..db49e10 100644 --- a/src/imports/lottieanimation.cpp +++ b/src/imports/lottieanimation.cpp @@ -566,7 +566,11 @@ bool LottieAnimation::loadSource(QString filename) } QByteArray json = sourceFile.readAll(); - parse(json); + if (Q_UNLIKELY(parse(json) == -1)) { + m_status = Error; + emit statusChanged(); + return false; + } setWidth(m_animWidth); emit widthChanged(); @@ -624,14 +628,18 @@ int LottieAnimation::parse(QByteArray jsonSource) { m_jsonSource = jsonSource; - QJsonDocument doc = QJsonDocument::fromJson(jsonSource); - QJsonObject rootObj = doc.object(); - - if (rootObj.empty()) { - m_status = Error; + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(m_jsonSource, &error); + if (Q_UNLIKELY(error.error != QJsonParseError::NoError)) { + qCWarning(lcLottieQtBodymovinParser) + << "JSON parse error:" << error.errorString(); return -1; } + QJsonObject rootObj = doc.object(); + if (Q_UNLIKELY(rootObj.empty())) + return -1; + m_startFrame = rootObj.value(QLatin1String("ip")).toVariant().toInt(); m_endFrame = rootObj.value(QLatin1String("op")).toVariant().toInt(); m_frameRate = rootObj.value(QLatin1String("fr")).toVariant().toInt(); |