From 57652a9084bcd0896a414c1a73bfc39396f5826e Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Mon, 15 Mar 2021 16:27:50 +0000 Subject: [PATCH] Version is strictly a string --- code/AssetLib/glTF2/glTF2Asset.inl | 9 +- test/models/glTF2/wrongTypes/BoxTextured0.bin | Bin 0 -> 840 bytes .../glTF2/wrongTypes/CesiumLogoFlat.png | Bin 0 -> 2433 bytes test/models/glTF2/wrongTypes/badArray.gltf | 179 +++++++++++++++++ .../models/glTF2/wrongTypes/badExtension.gltf | 185 ++++++++++++++++++ test/models/glTF2/wrongTypes/badNumber.gltf | 184 +++++++++++++++++ test/models/glTF2/wrongTypes/badObject.gltf | 176 +++++++++++++++++ test/models/glTF2/wrongTypes/badString.gltf | 182 +++++++++++++++++ test/models/glTF2/wrongTypes/badUint.gltf | 182 +++++++++++++++++ test/unit/utglTF2ImportExport.cpp | 24 +++ 10 files changed, 1113 insertions(+), 8 deletions(-) create mode 100644 test/models/glTF2/wrongTypes/BoxTextured0.bin create mode 100644 test/models/glTF2/wrongTypes/CesiumLogoFlat.png create mode 100644 test/models/glTF2/wrongTypes/badArray.gltf create mode 100644 test/models/glTF2/wrongTypes/badExtension.gltf create mode 100644 test/models/glTF2/wrongTypes/badNumber.gltf create mode 100644 test/models/glTF2/wrongTypes/badObject.gltf create mode 100644 test/models/glTF2/wrongTypes/badString.gltf create mode 100644 test/models/glTF2/wrongTypes/badUint.gltf diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 66b39ee57..8a88255c4 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -249,7 +249,7 @@ inline Value *FindObjectInContext(Value &val, const char *memberId, const char* inline Value *FindExtensionInContext(Value &val, const char *extensionId, const char* context, const char* extraContext = nullptr) { if (Value *extensionList = FindObjectInContext(val, "extensions", context, extraContext)) { - if (Value *extension = FindObjectInContext(*extensionList, extensionId, "extensions")) { + if (Value *extension = FindObjectInContext(*extensionList, extensionId, context, extraContext)) { return extension; } } @@ -1857,14 +1857,7 @@ inline void AssetMetadata::Read(Document &doc) { if (Value *versionString = FindStringInContext(*obj, "version", "\"asset\"")) { version = versionString->GetString(); - } else if (Value *versionNumber = FindNumberInContext(*obj, "version", "\"asset\"")) { - char buf[4]; - - ai_snprintf(buf, 4, "%.1f", versionNumber->GetDouble()); - - version = buf; } - Value *curProfile = FindObjectInContext(*obj, "profile", "\"asset\""); if (nullptr != curProfile) { ReadMember(*curProfile, "api", this->profile.api); diff --git a/test/models/glTF2/wrongTypes/BoxTextured0.bin b/test/models/glTF2/wrongTypes/BoxTextured0.bin new file mode 100644 index 0000000000000000000000000000000000000000..d2a73551f9456732c7ca85b9d70895f5d9ab8171 GIT binary patch literal 840 zcma)4TMmLS5FAugR8)K(r@fgRg`3F9)Sc2X4N+i|$-K6U9|D@%NdZH8sMCdXhgs?; z>8CE)+Yvq1hwmphbb0bSz9n3Qv{?B+?(fNy1()2HW=AbfwKB4_dS!i9PnJ%1er4>H zi~S!ZIHJM{XG4VxuDIcDxZ(qtxm=$B literal 0 HcmV?d00001 diff --git a/test/models/glTF2/wrongTypes/CesiumLogoFlat.png b/test/models/glTF2/wrongTypes/CesiumLogoFlat.png new file mode 100644 index 0000000000000000000000000000000000000000..45d502ed2610974189307ad542b05b70df14abd4 GIT binary patch literal 2433 zcmV-{34Zp8P)_WXpT zT&KN^W{xz{-NS2=JMQx8=kogA?fBT~_si45y2_@+&$ZLn&C25R(B<{I+3>&4t;yH7 z=k4F%=+?sB^4sOl<>lpUt>3WB;eWT|mc!+SyX3^v-*2zrrpV)YwBmHJ;knS^%huk~ z+1}aP+>XEHoyX^<&g`+&?tmWZ761SUi%CR5RCr$O)Jt;2APhy(Z08|~KgQ|(FDyew zsp=R5YT~nlTY~rX-#i|V$K!G2Wc)mlWh6Gnqti<0l$mFCVfs>HcWU= zU}N>)$8f~oL^fIRfxO@v@>XXMp-0e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yIg$lQO zx(rK>#?!52%-DnNO}C99+-~-4tJF!&d&yW%5pOT9a4Za>mBRBr4~%6L^Xd%8MuwAt zW*I9JR#H@RWw^gmlAPefWm2)lBSjsq4)<3oIiREU(w1y^C$V`S3HLi!D*DZS^HKhB z-YaTx-Y~vTY~lV&rRnC+#&}!`n0Hhst+)K~?bp~HKBXYsQz>P#*{iFndB=5%t3}eu zyJaE*!X5h0647#1nX*kzZ9aFxt9r&pTWVEERI0)~!d3uv zx`oUh2o9eP_tNLr*oYmY2Zk@r_@=_57K0U=t*JxdSRZ`rgl9iokOGFUU25j#hC9S?^-C5lI_BP0Qt)<=X(jOL|W7pUt>r>A!o%X z@co2A{I5!eGgi>%WLzbR5@frDOy5;+oAY(11Qoxd=UJcsgKAsLS-P7pesWtkxv|1P z5P(Z6S#BfSAYj-4UhrO&oM7&Mv@BT$2KrjZJwk9{`B+pT8DmQDz@><>-+!L z>tEMSJWt_oVwj8Nd3MGDj!&X+h~abS8HX(O#RO^i6gmL41?6#A&u5qfhs~Og;BbQH z6ErwO49jO{oU+wZ5WAM8GlG-C#KNsOZL4PUc5ly;HG&U_dCcFnj?3HOLmf+{@G(`* zW72SF|pWh(6ha+1#Q zUegee-PT&(#yCL<-ocN&gH|ibA?|uuzwO#F3cw%?h2bn>D#Qi@U7{I!2=9Ni&V_=s zT@><7S%1j*5*tj$sQk!EVlXA6{mT=^!U_{Z0U#c|HIOG8+R)*Q> wrongTypes = { + { "/glTF2/wrongTypes/badArray.gltf", "array", "meshes[0]" }, + { "/glTF2/wrongTypes/badString.gltf", "string", "scenes[0]" }, + { "/glTF2/wrongTypes/badUint.gltf", "uint", "materials[0]" }, + { "/glTF2/wrongTypes/badNumber.gltf", "number", "materials[0]" }, + { "/glTF2/wrongTypes/badObject.gltf", "object", "materials[0]" }, + { "/glTF2/wrongTypes/badExtension.gltf", "object", "materials[0]" } + }; + for (const auto& tuple : wrongTypes) + { + const auto& file = std::get<0>(tuple); + const auto& type = std::get<1>(tuple); + const auto& context = std::get<2>(tuple); + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR + file , aiProcess_ValidateDataStructure); + ASSERT_EQ(scene, nullptr); + const std::string error = importer.GetErrorString(); + EXPECT_FALSE(error.empty()); + EXPECT_NE(error.find(std::string("was not of type \"") + type + "\" when reading " + context), std::string::npos); + } +} +