0024176: Array out-of-bound error in Vrml loader (test bugs moddata_3 bug23023)
authorabv <abv@opencascade.com>
Mon, 16 Sep 2013 06:03:12 +0000 (10:03 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 26 Sep 2013 16:28:47 +0000 (20:28 +0400)
Code assigning normals to nodes of triangulation corrected to use correct index of the node and avoid array out-of-bound errors.

src/VrmlData/VrmlData_IndexedFaceSet.cxx
tests/bugs/moddata_3/bug23023

index b4d9dfa..164775f 100755 (executable)
@@ -173,24 +173,25 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
             Normals->SetValue (anIdx + 1, Standard_ShortReal (aNormal.Y ()));
             Normals->SetValue (anIdx + 2, Standard_ShortReal (aNormal.Z ()));
           }
-        } else {
-          nTri = 0;
-          for (i = 0; i < (int)myNbPolygons; i++) {
-            const Standard_Integer * arrIndice;
-            if (Polygon(i, arrIndice) == 3)
-              if (arrIndice[0] >= 0)  // check to avoid previously skipped faces
-                if (IndiceNormals(i, arrIndice) == 3) {
-                  Standard_Integer anInd = (++nTri - 1) * 3 + 1;
-                  for (Standard_Integer j = 0; j < 3; j++) {
-                    const gp_XYZ& aNormal = myNormals->Normal (arrIndice[j]);
-                    Normals->SetValue (anInd + 0 + j*3,
-                                       Standard_ShortReal (aNormal.X ()));
-                    Normals->SetValue (anInd + 1 + j*3,
-                                       Standard_ShortReal (aNormal.Y ()));
-                    Normals->SetValue (anInd + 2 + j*3,
-                                       Standard_ShortReal (aNormal.Z ()));
-                  }
+        }
+        else
+        {
+          for (i = 0; i < (int)myNbPolygons; i++) 
+          {
+            const Standard_Integer * arrNodes;
+            if (Polygon(i, arrNodes) == 3 && arrNodes[0] >= 0)  // check to avoid previously skipped faces
+            {
+              const Standard_Integer * arrIndice;
+              if (IndiceNormals(i, arrIndice) == 3) {
+                for (Standard_Integer j = 0; j < 3; j++) {
+                  const gp_XYZ& aNormal = myNormals->Normal (arrIndice[j]);
+                  Standard_Integer anInd = arrNodes[j] * 3 + 1;
+                  Normals->SetValue (anInd + 0, Standard_ShortReal (aNormal.X()));
+                  Normals->SetValue (anInd + 1, Standard_ShortReal (aNormal.Y()));
+                  Normals->SetValue (anInd + 2, Standard_ShortReal (aNormal.Z()));
                 }
+              }
+            }
           }
         }
       } else {
index f8456b9..480a2e4 100644 (file)
@@ -1,8 +1,3 @@
-puts "TODO ?OCC12345 ALL: An exception was caught"
-puts "TODO ?OCC12345 ALL: \\*\\* Exception \\*\\*.*"
-puts "TODO ?OCC12345 ALL: Faulty: VRML reader fails"
-##puts "TODO ?OCC12345 ALL: TEST INCOMPLETE"
-
 puts "========================"
 puts "OCC23023"
 puts "========================"
@@ -20,10 +15,3 @@ if [catch { set list [loadvrml result $filepath] } res] {
 } else {
     puts "OK: VRML reader work properly"
 }
-
-
-
-
-
-
-