Search Unity

Probuilder stack overflow on large mesh - ProBuilderize

Discussion in 'World Building' started by andyz, Sep 29, 2018.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,276
    This was a simple large terrain-style mesh and boom - broke

    Failed ProBuilderizing: Trr00
    System.StackOverflowException: The requested operation caused a stack overflow.
    at ProBuilder.Core.pb_Smoothing.FindSoftEdgesRecursive (UnityEngine.Vector3[] normals, ProBuilder.Core.pb_WingedEdge wing, Single angleThreshold, System.Collections.Generic.HashSet`1 processed) [0x00098] in C:\Users\karlh\procore\probuilder\probuilder2.0\Assets\ProCore\ProBuilder\Classes\ClassesCore\pb_Smoothing.cs:148
    at ProBuilder.Core.pb_Smoothing.FindSoftEdgesRecursive (UnityEngine.Vector3[] normals, ProBuilder.Core.pb_WingedEdge wing, Single angleThreshold, System.Collections.Generic.HashSet`1 processed) [0x00098] in C:\Users\karlh\procore\probuilder\probuilder2.0\Assets\ProCore\ProBuilder\Classes\ClassesCore\pb_Smoothing.cs:148
    at ProBuilder.Core.pb_Smoothing.FindSoftEdgesRecursive (UnityEngine.Vector3[] normals, ProBuilder.Core.pb_WingedEdge wing, Single angleThreshold, System.Collections.Generic.HashSet`1 processed) [0x00098] in C:\Users\karlh\procore\probuilder\probuilder2.0\Assets\ProCore\ProBuilder\Classes\ClassesCore\pb_Smoothing.cs:148
    ..........etc
     
  2. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    963
    Hi! Could you post a zip of the mesh for us to test directly? Thanks!
     
  3. LiamMitchell

    LiamMitchell

    Joined:
    Oct 30, 2015
    Posts:
    5
    I'm encountering this error as well, but I don't have a mesh to share as I am loading it at runtime (in the editor) from a non standard format.

    Pro Builder 4.4.0

    I attempted to save the mesh out with MeshSeralizer.
    https://github.com/pharan/Unity-MeshSaver/blob/master/MeshSaver/Editor/MeshSaverEditor.cs
    This does not appear to save materials, and when I imported it and probuilderized it did appear to get further but created a mess of spider web/cluster of edges that were not previously there.

    I thought this could be because the MeshSeralizer did not preserve the indexFormat property being UInt32 or due to the use of MeshUtility.Optimize but does not appear to be the case as I tried again with that set to false.

    Maybe there is a way Unity can do an FBX export.

    Before
    upload_2021-1-1_20-35-12.png

    After (When clicking on the game object)
    upload_2021-1-1_20-40-40.png

    Exception from importing the mesh to probuilderize.
    upload_2021-1-1_20-36-27.png

    Could this be caused by too much recursion or some kind of circular reference issue?
    Is there a way to make probuilderizing / importing the mesh not use recursive methods?
    Such as:
    https://www.refactoring.com/catalog/replaceRecursionWithIteration.html
    https://haacked.com/archive/2007/03/04/Replacing_Recursion_With_a_Stack.aspx/

    A way to do this async or in another thread would be nice as well, does Probuilder API have to be run on the main thread?

    Is there a mesh import setting I can set to skip the Smoothing code just to check if it works without it?

    Edit: Figured out how to disable smoothing, which does not have an exception anymore but still creates the spiderweb mess of edges.
    Code (CSharp):
    1.  
    2. var importSettings = new MeshImportSettings();
    3. importSettings.smoothing = false;
    4. importer.Import(importSettings);
    5.  
    I'm afraid it is beyond my understanding at this point and seems like it could be a bug?
    I would have to dive deeper into Probuilders code to see how it works.

    Code I'm using when loading this mesh to probuliderize it.

    Code (CSharp):
    1. // TODO: Make this probuilder in editor?
    2. // https://github.com/Unity-Technologies/ProBuilder-API-Examples/blob/master/Runtime/Convert%20Mesh%20to%20Editable/MakePrimitiveEditable.cs
    3. if (Application.isEditor)
    4. {
    5.     // For example on making a primitive editable in pro builder see https://github.com/Unity-Technologies/com.unity.probuilder/blob/master/Samples~/Runtime/Convert%20Mesh%20to%20Editable/MakePrimitiveEditable.cs
    6.  
    7.     // Import from a GameObject. In this case we're loading and assigning to the same GameObject, but you may
    8.     // load and apply to different Objects as well.
    9.  
    10.     // Create a new MeshImporter.
    11.     var importer = new MeshImporter(terrain);
    12.     importer.Import();
    13.  
    14.     // Since we're loading and setting from the same object, it is necessary to create a new mesh to avoid
    15.     // overwriting the mesh that is being read from.
    16.     meshFilter.sharedMesh = new Mesh();
    17.  
    18.     //Retrieve or create the PB Mesh.
    19.     var mesh = terrain.GetComponent<ProBuilderMesh>();
    20.     if (mesh == null)
    21.     {
    22.         mesh = terrain.AddComponent<ProBuilderMesh>();
    23.     }
    24.  
    25.     // Do something with the pb_Object. Here we're extruding every face on the object by .25.
    26.     //mesh.Extrude(mesh.faces, ExtrudeMethod.IndividualFaces, .25f);
    27.  
    28.     // Apply the imported geometry to the pb_Object
    29.     mesh.ToMesh();
    30.  
    31.     // Rebuild UVs, Collisions, Tangents, etc.
    32.     mesh.Refresh();
    33. }

    Thinking that it might be due to IndexFormat of the mesh having more than max short of verts.
    https://forum.unity.com/threads/probuilderize-limitations-max-tris.595504/

    Related?
    https://issuetracker.unity3d.com/is...s-a-stackoverflowexception-with-specific-mesh

    But I'm using Pro Builder 4.4.0
     
    Last edited: Jan 1, 2021
  4. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    963
    Hi! I can't help with that external tool ... but I think you could just use ProBuilder's built-in exporting?

    1. Select a PB object (ensure you are in Object Mode)
    2. Click the "+" next to "Export"
    3. Choose "Asset" if you just want a simple mesh asset, or OBJ, etc

    Note that FBX will only appear in this list if you have the "FBX Exporter" Package installed.

    Hope that helps!