From cccf81ea2a87f3f192ec92ea880c18c275a2ccc0 Mon Sep 17 00:00:00 2001 From: abv Date: Mon, 16 Sep 2013 10:03:12 +0400 Subject: [PATCH] 0024176: Array out-of-bound error in Vrml loader (test bugs moddata_3 bug23023) 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 | 35 ++++++++++++------------ tests/bugs/moddata_3/bug23023 | 12 -------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/VrmlData/VrmlData_IndexedFaceSet.cxx b/src/VrmlData/VrmlData_IndexedFaceSet.cxx index b4d9dfa3a4..164775f5de 100755 --- a/src/VrmlData/VrmlData_IndexedFaceSet.cxx +++ b/src/VrmlData/VrmlData_IndexedFaceSet.cxx @@ -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 { diff --git a/tests/bugs/moddata_3/bug23023 b/tests/bugs/moddata_3/bug23023 index f8456b9f2c..480a2e4d55 100644 --- a/tests/bugs/moddata_3/bug23023 +++ b/tests/bugs/moddata_3/bug23023 @@ -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" } - - - - - - -