Skip to content

Off-by-one error in TriangleMesh::removeUnusedVertices #406

Open
@glhrmfrts

Description

@glhrmfrts

Hello, I download latest master just today.

I was trying to create a TriangleMesh to use with ConcaveMeshShape and I kept getting a {0,0,0} normal at index 0, which in turn crashed the application with an assertion failure.

My mesh doesn't use all the vertices provided because I have a shared vertex/normal buffer and several sub-meshes with different indices. This caused the TriangleMesh to have a lot of unused vertices.

The problem is in here: https://github.com/DanielChappuis/reactphysics3d/blob/master/src/collision/TriangleMesh.cpp#L220

Because of the i > 0 condition in the for loop, if the first vertex is not used, it is not removed from the mesh, which causes a zero-length normal to be leftover and causes more problems down the line.

I fixed by changing the type of i to int64 and using a i >= 0 condition:

for (int64 i = mVertices.size() - 1; i >= 0; i--)

Ofc you can also keep the uint32 type and use a i < mVertices.size() condition, but I didn't like to rely on the unsigned number wrapping around.

If you want I can open a PR.

Thanks for the great library!

Metadata

Metadata

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions