Skip to content

Conversation

@Aleph0x
Copy link
Contributor

@Aleph0x Aleph0x commented Dec 27, 2025

Selecting mesh elements (edges, faces, vertices) with trace logging enabled could flood the console and eventually crash with:

System.InsufficientExecutionStackException: Insufficient stack to continue executing the program safely.

This fixes the cause by changing ToString() on mesh selection wrapper types so they no longer invoke handle ToString() implementations that recursively walk/traverse the half-edge mesh structure.

The mesh selection wrapper types MeshEdge, MeshFace, and MeshVertex were formatting their underlying handle objects directly inside interpolated strings.

MeshEdge.ToString() included {Handle} where Handle is a HalfEdgeHandle

MeshFace.ToString() included {Handle} where Handle is a FaceHandle

MeshVertex.ToString() included {Handle} where Handle is a VertexHandle

Interpolating {Handle} calls Handle.ToString().

From the stacktraces, those handle ToString() implementations go through PrintMembers(StringBuilder ...), typical of record style or debugger display helpers. Those routines then stringify connected handles. Half edges reference vertices, vertices reference half edges, and so on. So we end up with an unbounded call stack until the runtime throws InsufficientExecutionStackException or at least until Trace Logging is disabled in the scene editor.

Error calling event 'tool.frame' on 'Editor.SceneViewWidget'
System.InsufficientExecutionStackException: Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.
     at HalfEdgeMesh.HalfEdgeHandle.PrintMembers(StringBuilder builder)
   at HalfEdgeMesh.HalfEdgeHandle.ToString()
   at HalfEdgeMesh.VertexHandle.PrintMembers(StringBuilder builder)
   at HalfEdgeMesh.VertexHandle.ToString()
   ...
   at System.Runtime.CompilerServices.DefaultInterpolatedStringHandler.AppendFormatted[T](T value)
   at Editor.MeshEditor.MeshEdge.ToString() in C:\program files (x86)\steam\steamapps\common\sbox\addons\tools\code\Scene\Mesh\MeshEdge.cs:line 36
   at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at Editor.TreeView.ScrollTo(Object target) in C:\program files (x86)\steam\steamapps\common\sbox\addons\tools\code\Widgets\TreeView\TreeView.cs:line 706
   at Editor.SceneTreeWidget.OnInspect(OnInspectArgs args) in C:\program files (x86)\steam\steamapps\common\sbox\addons\tools\code\Scene\SceneTree\SceneTree.cs:line 262
   at Editor.EditorUtility.set_InspectorObject(Object value)
   at Editor.SceneViewWidget.Frame() in C:\program files (x86)\steam\steamapps\common\sbox\addons\tools\code\Scene\SceneView\SceneViewWidget.cs:line 96
   at InvokeStub_SceneViewWidget.Frame(Object, Object, IntPtr*)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

MeshFace.ToString() was interpolating {Handle}, which calls FaceHandle.ToString() / PrintMembers(...) and can recurse through half-edge refs. This caused InsufficientExecutionStackException when the inspector or TreeView.ScrollTo(...) formats selected faces, especially with trace logging. Switched ToString() to a stable identifier (HandleIndex) and guard the object name to prevent recursive stringification.
Prevents InsufficientExecutionStackException spam when selecting vertices with trace logging enabled
@aylaylay
Copy link
Contributor

I'd rather the handles just had a tostring for the index incase they get logged by someone

@Aleph0x
Copy link
Contributor Author

Aleph0x commented Dec 27, 2025

I'd rather the handles just had a tostring for the index incase they get logged by someone

I’ll shift the fix

Copy link
Contributor

@aylaylay aylaylay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put these on single line

I kept ToString() to just the index so it stays a low-level identity string. Higher-level tools can add whatever labeling or context they need
@Aleph0x Aleph0x force-pushed the fix/mesh-handle-tostring-recursion branch from c186164 to 365eb5a Compare December 27, 2025 17:51
@Aleph0x Aleph0x requested a review from aylaylay December 27, 2025 17:51
@aylaylay aylaylay added the triaged triaged pull-requests are replicated on the internal sbox repo label Dec 27, 2025
@Aleph0x
Copy link
Contributor Author

Aleph0x commented Dec 29, 2025

@Aleph0x Aleph0x closed this Dec 29, 2025
@aylaylay aylaylay removed the triaged triaged pull-requests are replicated on the internal sbox repo label Dec 29, 2025
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

Successfully merging this pull request may close these issues.

2 participants