]> OCCT Git - occt.git/commitdiff
Data Exchange, GLTF Reader - Fix indices during parsering of arrays (#602)
authorsshutina <svetlana.shutina@opencascade.com>
Mon, 14 Jul 2025 10:04:03 +0000 (11:04 +0100)
committerGitHub <noreply@github.com>
Mon, 14 Jul 2025 10:04:03 +0000 (11:04 +0100)
- Use the loop index (`anIndex` or `i`) instead of always reading `theValue[0]`.
- Preserve existing behavior of array allocation and string concatenation.
- Updated three loops in `RWGltf_GltfJsonParser.cxx` to reference the correct element.

src/DataExchange/TKDEGLTF/RWGltf/RWGltf_GltfJsonParser.cxx

index e517be7bf546cbb726a2585183c8c4a37a559e45..8eedcef27e12f011f7a79f22e0cd414b94dce56a 100644 (file)
@@ -276,7 +276,8 @@ bool RWGltf_ExtrasParser::parseArray(const RWGltf_JsonValue& theValue,
     Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(0, theValue.Size());
     for (size_t anIndex = 0; anIndex < theValue.Size(); ++anIndex)
     {
-      anArray->SetValue(static_cast<Standard_Integer>(anIndex), theValue[0].GetInt());
+      anArray->SetValue(static_cast<Standard_Integer>(anIndex),
+                        theValue[static_cast<Standard_Integer>(anIndex)].GetInt());
     }
     getResult()->SetArrayOfIntegers(theValueName.c_str(), anArray);
     return true;
@@ -287,7 +288,8 @@ bool RWGltf_ExtrasParser::parseArray(const RWGltf_JsonValue& theValue,
     Handle(TColStd_HArray1OfReal) anArray = new TColStd_HArray1OfReal(0, theValue.Size());
     for (size_t anIndex = 0; anIndex < theValue.Size(); ++anIndex)
     {
-      anArray->SetValue(static_cast<Standard_Integer>(anIndex), theValue[0].GetDouble());
+      anArray->SetValue(static_cast<Standard_Integer>(anIndex),
+                        theValue[static_cast<Standard_Integer>(anIndex)].GetDouble());
     }
     getResult()->SetArrayOfReals(theValueName.c_str(), anArray);
     return true;
@@ -302,7 +304,8 @@ bool RWGltf_ExtrasParser::parseArray(const RWGltf_JsonValue& theValue,
     const std::string aSeparator = ";";
     for (size_t i = 0; i < theValue.Size(); ++i)
     {
-      anArrayString = anArrayString + aSeparator + theValue[0].GetString();
+      anArrayString =
+        anArrayString + aSeparator + theValue[static_cast<Standard_Integer>(i)].GetString();
     }
     getResult()->SetString(theValueName.c_str(), anArrayString.c_str());
     return true;