Gracefully handle NaNs and Infs in gltf2 accessor bound computation

pull/3214/head
Jeremy Cytryn 2020-05-06 23:59:48 -07:00
parent aef4ecada5
commit c5a9fbd47f
2 changed files with 12 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* /*
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -172,6 +172,13 @@ void SetAccessorRange(Ref<Accessor> acc, void* data, size_t count,
for (unsigned int j = 0 ; j < numCompsOut ; j++) { for (unsigned int j = 0 ; j < numCompsOut ; j++) {
double valueTmp = buffer_ptr[j]; double valueTmp = buffer_ptr[j];
// Gracefully tolerate rogue NaN's in buffer data
// Any NaNs/Infs introduced in accessor bounds will end up in
// document and prevent rapidjson from writing out valid JSON
if (!std::isfinite(valueTmp)) {
continue;
}
if (valueTmp < acc->min[j]) { if (valueTmp < acc->min[j]) {
acc->min[j] = valueTmp; acc->min[j] = valueTmp;
} }

View File

@ -442,8 +442,8 @@ TEST_F(utglTF2ImportExport, export_bad_accessor_bounds) {
const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites.glb", aiProcess_ValidateDataStructure); const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites.glb", aiProcess_ValidateDataStructure);
ASSERT_NE(scene, nullptr); ASSERT_NE(scene, nullptr);
EXPECT_EQ(aiReturn_FAILURE, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.glb")); EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.glb"));
EXPECT_EQ(aiReturn_FAILURE, exporter.Export(scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.gltf")); EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.gltf"));
} }
#endif // ASSIMP_BUILD_NO_EXPORT #endif // ASSIMP_BUILD_NO_EXPORT