mirror of
https://github.com/overte-org/overte.git
synced 2025-06-03 21:11:31 +02:00
Check results of qUncompress, and catch fbx reader throws in utility
programs.
This commit is contained in:
parent
b72c28854c
commit
51a4154ae7
3 changed files with 28 additions and 16 deletions
|
@ -105,13 +105,18 @@ bool ModelPackager::loadModel() {
|
||||||
qWarning() << QString("ModelPackager::loadModel(): Could not open FBX file %1").arg(_fbxInfo.filePath());
|
qWarning() << QString("ModelPackager::loadModel(): Could not open FBX file %1").arg(_fbxInfo.filePath());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath();
|
try {
|
||||||
QByteArray fbxContents = fbx.readAll();
|
qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath();
|
||||||
|
QByteArray fbxContents = fbx.readAll();
|
||||||
|
|
||||||
_geometry.reset(readFBX(fbxContents, QVariantHash(), _fbxInfo.filePath()));
|
_geometry.reset(readFBX(fbxContents, QVariantHash(), _fbxInfo.filePath()));
|
||||||
|
|
||||||
// make sure we have some basic mappings
|
// make sure we have some basic mappings
|
||||||
populateBasicMapping(_mapping, _fbxInfo.filePath(), *_geometry);
|
populateBasicMapping(_mapping, _fbxInfo.filePath(), *_geometry);
|
||||||
|
} catch (const QString& error) {
|
||||||
|
qCDebug(interfaceapp) << "Error reading " << _fbxInfo.filePath() << ": " << error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,9 @@ template<class T> QVariant readBinaryArray(QDataStream& in, int& position) {
|
||||||
in.readRawData(compressed.data() + sizeof(quint32), compressedLength);
|
in.readRawData(compressed.data() + sizeof(quint32), compressedLength);
|
||||||
position += compressedLength;
|
position += compressedLength;
|
||||||
QByteArray uncompressed = qUncompress(compressed);
|
QByteArray uncompressed = qUncompress(compressed);
|
||||||
|
if (uncompressed.isEmpty()) { // answers empty byte array if corrupt
|
||||||
|
throw QString("corrupt fbx file");
|
||||||
|
}
|
||||||
QDataStream uncompressedIn(uncompressed);
|
QDataStream uncompressedIn(uncompressed);
|
||||||
uncompressedIn.setByteOrder(QDataStream::LittleEndian);
|
uncompressedIn.setByteOrder(QDataStream::LittleEndian);
|
||||||
uncompressedIn.setVersion(QDataStream::Qt_4_5); // for single/double precision switch
|
uncompressedIn.setVersion(QDataStream::Qt_4_5); // for single/double precision switch
|
||||||
|
|
|
@ -34,20 +34,24 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, FBXGeometry& result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::cout << "Reading FBX.....\n";
|
std::cout << "Reading FBX.....\n";
|
||||||
|
try {
|
||||||
|
QByteArray fbxContents = fbx.readAll();
|
||||||
|
FBXGeometry* geom;
|
||||||
|
if (filename.toLower().endsWith(".obj")) {
|
||||||
|
geom = OBJReader().readOBJ(fbxContents, QVariantHash());
|
||||||
|
} else if (filename.toLower().endsWith(".fbx")) {
|
||||||
|
geom = readFBX(fbxContents, QVariantHash(), filename);
|
||||||
|
} else {
|
||||||
|
qDebug() << "unknown file extension";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
result = *geom;
|
||||||
|
|
||||||
QByteArray fbxContents = fbx.readAll();
|
reSortFBXGeometryMeshes(result);
|
||||||
FBXGeometry* geom;
|
} catch (const QString& error) {
|
||||||
if (filename.toLower().endsWith(".obj")) {
|
qDebug() << "Error reading " << filename << ": " << error;
|
||||||
geom = OBJReader().readOBJ(fbxContents, QVariantHash());
|
|
||||||
} else if (filename.toLower().endsWith(".fbx")) {
|
|
||||||
geom = readFBX(fbxContents, QVariantHash(), filename);
|
|
||||||
} else {
|
|
||||||
qDebug() << "unknown file extension";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
result = *geom;
|
|
||||||
|
|
||||||
reSortFBXGeometryMeshes(result);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue