fix issue where probuilder with quad topology instead of triangle would trigger out of bounds exception when being exported #619
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose of this PR
The degenerate triangle removal code introduced in v6.0.6 assumed all submeshes used triangular topology,
but ProBuilder meshes can contain mixed topologies (triangles, quads, etc.). The code incremented through indices
by 3 and accessed
indexes[tri + 2]
, causing IndexOutOfRangeException when processing non-triangular submesheslike quads with indices arrays not divisible by 3. This specifically affected shapes like Door that use quad topology.
Fix: Added a topology check
if (submeshes[i].m_Topology == MeshTopology.Triangles)
before applying thedegenerate triangle removal logic. This ensures the triangle-specific degenerate detection only runs on actual
triangular submeshes, preventing the index bounds violation on quad/other topologies.
Preserves Original Fix: The degenerate triangle removal functionality remains completely intact for triangular
submeshes - it still detects and removes zero-area triangles using cross-product magnitude checks. Non-triangular
submeshes bypass this processing entirely, which is appropriate since the concept of "degenerate triangles" doesn't
apply to quads or other topologies. The fix maintains backward compatibility while eliminating the crash.
Result: Door shapes and other mixed-topology meshes can now be exported without IndexOutOfRangeException,
while triangular meshes continue to benefit from degenerate triangle cleanup and improved rendering quality.
Links
https://jira.unity3d.com/browse/PBLD-251
Comments to Reviewers
I did not check for degenerate quads in this PR, because I could not repro the issue the user was having with degenerate triangles (making the bloom flash weirdly)