From 13a232aa9b5c44ddd461bab60279c6b481faa45f Mon Sep 17 00:00:00 2001 From: cutealien Date: Tue, 26 May 2020 13:01:02 +0000 Subject: [PATCH] updateTriangles in CTriangleSelector can handle some broken meshes without crash now. Before it crashed when index-count wasn't a multiple of 3, now it just doesn't create the last triangle then. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6110 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CTriangleSelector.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/Irrlicht/CTriangleSelector.cpp b/source/Irrlicht/CTriangleSelector.cpp index 0342b349..531c62d6 100644 --- a/source/Irrlicht/CTriangleSelector.cpp +++ b/source/Irrlicht/CTriangleSelector.cpp @@ -127,22 +127,22 @@ static void updateTriangles(u32& triangleCount, core::array& { if ( bufferTransform ) { - for (u32 index = 0; index < idxCnt; index += 3) + for (u32 index = 2; index < idxCnt; index += 3) { core::triangle3df& tri = triangles[triangleCount++]; - bufferTransform->transformVect( tri.pointA, (*reinterpret_cast(&vertices[indices[index + 0]*vertexPitch])).Pos ); - bufferTransform->transformVect( tri.pointB, (*reinterpret_cast(&vertices[indices[index + 1]*vertexPitch])).Pos ); - bufferTransform->transformVect( tri.pointC, (*reinterpret_cast(&vertices[indices[index + 2]*vertexPitch])).Pos ); + bufferTransform->transformVect( tri.pointA, (*reinterpret_cast(&vertices[indices[index - 2]*vertexPitch])).Pos ); + bufferTransform->transformVect( tri.pointB, (*reinterpret_cast(&vertices[indices[index - 1]*vertexPitch])).Pos ); + bufferTransform->transformVect( tri.pointC, (*reinterpret_cast(&vertices[indices[index - 0]*vertexPitch])).Pos ); } } else { - for (u32 index = 0; index < idxCnt; index += 3) + for (u32 index = 2; index < idxCnt; index += 3) { core::triangle3df& tri = triangles[triangleCount++]; - tri.pointA = (*reinterpret_cast(&vertices[indices[index + 0]*vertexPitch])).Pos; - tri.pointB = (*reinterpret_cast(&vertices[indices[index + 1]*vertexPitch])).Pos; - tri.pointC = (*reinterpret_cast(&vertices[indices[index + 2]*vertexPitch])).Pos; + tri.pointA = (*reinterpret_cast(&vertices[indices[index - 2]*vertexPitch])).Pos; + tri.pointB = (*reinterpret_cast(&vertices[indices[index - 1]*vertexPitch])).Pos; + tri.pointC = (*reinterpret_cast(&vertices[indices[index - 0]*vertexPitch])).Pos; } } }