mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 15:43:17 +02:00
Fix import of invalid JSON file failing silently
This commit is contained in:
parent
ae9b8696d4
commit
2953ca08cb
2 changed files with 10 additions and 3 deletions
|
@ -1430,6 +1430,12 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
|||
QVariantList entitiesQList = map["Entities"].toList();
|
||||
QScriptEngine scriptEngine;
|
||||
|
||||
if (entitiesQList.length() == 0) {
|
||||
// Empty map or invalidly formed file.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success = true;
|
||||
foreach (QVariant entityVariant, entitiesQList) {
|
||||
// QVariantMap --> QScriptValue --> EntityItemProperties --> Entity
|
||||
QVariantMap entityMap = entityVariant.toMap();
|
||||
|
@ -1447,9 +1453,10 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
|||
EntityItemPointer entity = addEntity(entityItemID, properties);
|
||||
if (!entity) {
|
||||
qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType();
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
void EntityTree::resetClientEditStats() {
|
||||
|
|
|
@ -1863,9 +1863,9 @@ bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputSt
|
|||
QJsonDocument asDocument = QJsonDocument::fromJson(jsonBuffer);
|
||||
QVariant asVariant = asDocument.toVariant();
|
||||
QVariantMap asMap = asVariant.toMap();
|
||||
readFromMap(asMap);
|
||||
bool success = readFromMap(asMap);
|
||||
delete[] rawData;
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
void Octree::writeToFile(const char* fileName, OctreeElementPointer element, QString persistAsFileType) {
|
||||
|
|
Loading…
Reference in a new issue