diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index dc2235ba2..660d52b9f 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -185,7 +185,7 @@ void SetAccessorRange(Ref acc, void *data, size_t count, // Allocate and initialize with large values. for (unsigned int i = 0; i < numCompsOut; i++) { - acc->min.push_back(std::numeric_limits::max()); + acc->min.push_back(std::numeric_limits::min()); acc->max.push_back(-std::numeric_limits::max()); } diff --git a/code/AssetLib/glTFCommon/glTFCommon.h b/code/AssetLib/glTFCommon/glTFCommon.h index da2a50768..3729f3ac4 100644 --- a/code/AssetLib/glTFCommon/glTFCommon.h +++ b/code/AssetLib/glTFCommon/glTFCommon.h @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER #include +#include #include #include @@ -444,7 +445,7 @@ inline Value *FindArrayInContext(Value &val, const char *memberId, const char *c return &it->value; } -inline Value *FindObjectInContext(Value &val, const char *memberId, const char *context, const char *extraContext = nullptr) { +inline Value *FindObjectInContext(Value &val, const char * memberId, const char *context, const char *extraContext = nullptr) { if (!val.IsObject()) { return nullptr; } @@ -453,8 +454,9 @@ inline Value *FindObjectInContext(Value &val, const char *memberId, const char * return nullptr; } if (!it->value.IsObject()) { - throwUnexpectedTypeError("object", memberId, context, extraContext); - } + ASSIMP_LOG_ERROR("Member \"", memberId, "\" was not of type \"", context, "\" when reading ", extraContext); + return nullptr; + } return &it->value; } diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index ca24c563f..bce57976a 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -933,8 +933,8 @@ TEST_F(utglTF2ImportExport, wrongTypes) { TUPLE("/glTF2/wrongTypes/badString.gltf", "string", "name", "scenes[0]"), TUPLE("/glTF2/wrongTypes/badUint.gltf", "uint", "index", "materials[0]"), TUPLE("/glTF2/wrongTypes/badNumber.gltf", "number", "scale", "materials[0]"), - TUPLE("/glTF2/wrongTypes/badObject.gltf", "object", "pbrMetallicRoughness", "materials[0]"), - TUPLE("/glTF2/wrongTypes/badExtension.gltf", "object", "KHR_texture_transform", "materials[0]") + //TUPLE("/glTF2/wrongTypes/badObject.gltf", "object", "pbrMetallicRoughness", "materials[0]"), + //TUPLE("/glTF2/wrongTypes/badExtension.gltf", "object", "KHR_texture_transform", "materials[0]") #undef TUPLE }; for (const auto& tuple : wrongTypes) @@ -952,6 +952,28 @@ TEST_F(utglTF2ImportExport, wrongTypes) { } } +TEST_F(utglTF2ImportExport, wrongObject) { + // Deliberately broken version of the BoxTextured.gltf asset. + using tup_T = std::tuple; + std::vector wrongTypes = { +#ifdef __cpp_lib_constexpr_tuple +#define TUPLE(x, y, z, w) \ + { x, y, z, w } +#else +#define TUPLE(x, y, z, w) tup_T(x, y, z, w) +#endif + TUPLE("/glTF2/wrongTypes/badObject.gltf", "object", "pbrMetallicRoughness", "materials[0]"), + TUPLE("/glTF2/wrongTypes/badExtension.gltf", "object", "KHR_texture_transform", "materials[0]") +#undef TUPLE + }; + for (const auto &tuple : wrongTypes) { + const auto &file = std::get<0>(tuple); + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR + file, aiProcess_ValidateDataStructure); + ASSERT_NE(scene, nullptr); + } +} + namespace { /// This class provides a fake schema to the GLTF importer. /// It just checks that the file has a top-level "scene" property which is an integer.