Skip to content

Fix the stack overflow when drawing a long polyline - #446

Merged
doranteseduardo merged 1 commit into
developfrom
fix/polyline-stack-overflow
Nov 6, 2026
Merged

doranteseduardo merged 1 commit into
developfrom
fix/polyline-stack-overflow

Conversation

@doranteseduardo

Copy link
Copy Markdown
Member

Summary

A crash on iOS when the world mesh's debug drawing is on: VROPolyline::buildElement built its index list as a variable-length array on the stack.

Cause

  • VROPencil::render (the world mesh's debugDrawEnabled) turns every mesh edge into one polyline each frame. buildElement then declared int indices[numCorners] on the stack.
  • With 3.1.0's accumulated world mesh, a room reaches hundreds of thousands of corners, so the array overflowed the iOS main thread's stack.
  • The crash: EXC_BAD_ACCESS, "Thread stack size exceeded", in ___chkstk_darwin ← VROPolyline::buildElement ← VROPencil::render, on an iPhone 16 Pro running the showcase world mesh scene.

Fix

  • VROPolyline::buildElement and VROPolygon::buildElement, which has the same unbounded stack array, build their indices in a std::vector.
  • VROData copies the bytes by default, so the vector can go once the element is built.

Notes

  • Debug drawing a large accumulated mesh is still expensive, since every edge is redrawn each frame. It is a debugging aid; the showcase scene now starts with it off.
  • CHANGELOG (3.1.0) updated.

Testing

  • Built with scripts/build.sh (Android AAR, iOS device and simulator). The rebuilt binaries ship in viro's companion PR.

@doranteseduardo
doranteseduardo merged commit f0581dc into develop Nov 6, 2026
4 checks passed
@doranteseduardo
doranteseduardo deleted the fix/polyline-stack-overflow branch November 6, 2026 02:12
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