mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +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();
|
QVariantList entitiesQList = map["Entities"].toList();
|
||||||
QScriptEngine scriptEngine;
|
QScriptEngine scriptEngine;
|
||||||
|
|
||||||
|
if (entitiesQList.length() == 0) {
|
||||||
|
// Empty map or invalidly formed file.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = true;
|
||||||
foreach (QVariant entityVariant, entitiesQList) {
|
foreach (QVariant entityVariant, entitiesQList) {
|
||||||
// QVariantMap --> QScriptValue --> EntityItemProperties --> Entity
|
// QVariantMap --> QScriptValue --> EntityItemProperties --> Entity
|
||||||
QVariantMap entityMap = entityVariant.toMap();
|
QVariantMap entityMap = entityVariant.toMap();
|
||||||
|
@ -1447,9 +1453,10 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
||||||
EntityItemPointer entity = addEntity(entityItemID, properties);
|
EntityItemPointer entity = addEntity(entityItemID, properties);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType();
|
qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType();
|
||||||
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::resetClientEditStats() {
|
void EntityTree::resetClientEditStats() {
|
||||||
|
|
|
@ -1863,9 +1863,9 @@ bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputSt
|
||||||
QJsonDocument asDocument = QJsonDocument::fromJson(jsonBuffer);
|
QJsonDocument asDocument = QJsonDocument::fromJson(jsonBuffer);
|
||||||
QVariant asVariant = asDocument.toVariant();
|
QVariant asVariant = asDocument.toVariant();
|
||||||
QVariantMap asMap = asVariant.toMap();
|
QVariantMap asMap = asVariant.toMap();
|
||||||
readFromMap(asMap);
|
bool success = readFromMap(asMap);
|
||||||
delete[] rawData;
|
delete[] rawData;
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::writeToFile(const char* fileName, OctreeElementPointer element, QString persistAsFileType) {
|
void Octree::writeToFile(const char* fileName, OctreeElementPointer element, QString persistAsFileType) {
|
||||||
|
|
Loading…
Reference in a new issue