Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
glhrmfrts opened this issue Oct 23, 2024 · 0 comments
Open

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

glhrmfrts opened this issue Oct 23, 2024 · 0 comments

Comments

@glhrmfrts
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant