Geometry script blueprint using ApplySimplifyToTolerance -> ApplySimplifyToPlanar nodes crashes on load

The issue seems to be related to the TDynamicMeshOverlay::CompactInPlace() function.

I have not thoroughly investigated the issue, but it seems to follow along these lines:

  • The `ApplySimplifyToTolerance` node is run on an empty mesh.
  • A math error grows `ElementTriangles` from 0 to 3 elements, creating an invalid triangle in the previously empty mesh.
    • See the the code snippet below. Note `ElementTriangles.Num() == 0` and `MaxNewTID == 0`
    • As you can see there is a checkSlow() which would catch this in a debug build, and a comment mentioning this should never happen.
  • The `ApplySimplifyToPlanar` node is run on the mesh outputted from the `ApplySimplifyToTolerance`.
  • Code in the `ApplySimplifyToPlanar` node tries to index something based on the newly created, invalid triangle indices, crashing the editor.

DynamicMeshOverlay.h, L242:

// ElementTriangles should never grow during a compaction, so just resizing is ok
 // (i.e., we shouldn't need to set InvalidID on any added triangles)
 checkSlow(ElementTriangles.Num() >= (MaxNewTID + 1) * 3);
 ElementTriangles.Resize((MaxNewTID + 1) * 3);

Steps to Reproduce
Open the repro project and open the blueprint BP_PCG_GeneratedBounds in the root content folder. The editor crashes.

Hi Frederik,

Thank you for reporting this issue and providing a small repro project. I was able to repro this crash on my end here. Moreover, after looking through the source code, I can see that your assessment is correct about the root cause of the problem.

The fix for this is very simple, and it has already been integrated into UE 5.6, where the crash does not repro anymore. Just a little above the snippet you provided, just look for the following code and change the initialization of MaxNewTID from 0 to -1:

// Remap and compact triangle element indices.
int32 MaxNewTID = 0;

If you’d like to cherry-pick the official fix, you can find it on CL 38005241 in ue5-main, and on GitHub commit 538e383.

By the way, if you are not building from source and would like to recover that blueprint asset, I have attached a fixed-up version to this post (compatible with UE 5.5).

Let me know if you need any further assistance!

Best regards,

Vitor