Skip to content

fix: prevent browser freeze when tessellating >50k vertices (#8219 )#8555

Open
Nixxx19 wants to merge 3 commits intoprocessing:mainfrom
Nixxx19:nityam/tessellation-freeze-fix
Open

fix: prevent browser freeze when tessellating >50k vertices (#8219 )#8555
Nixxx19 wants to merge 3 commits intoprocessing:mainfrom
Nixxx19:nityam/tessellation-freeze-fix

Conversation

@Nixxx19
Copy link
Copy Markdown

@Nixxx19 Nixxx19 commented Feb 22, 2026

Resolves #8219

Summary

  • Adds a one‑time confirmation prompt before tessellating very large TESS shapes (>50,000 vertices) to avoid browser freezes in libtess during _triangulate().
  • Cancel: skips tessellation and draws nothing for that shape (no TRIANGLE_FAN fallback), keeping behavior explicit and predictable.
  • OK: remembers the choice for the lifetime of the renderer via _largeTessellationAcknowledged and tessellates normally without prompting again.
  • Respects p5.disableFriendlyErrors / minified builds: when friendly errors are disabled, tessellation always runs with no prompt.

Tests

  • Adds / updates WebGL unit tests in test/unit/webgl/p5.RendererGL.js to cover:
    • Prompting once for large shapes and including the vertex count in the message.
    • Skipping tessellation entirely on cancel (no TRIANGLE_FAN fallback).
    • Only prompting once per renderer when the user approves.
    • Skipping the prompt when p5.disableFriendlyErrors is true.
    • Normal tessellation behavior for shapes below the 50k‑vertex threshold.

Screenshot

Screenshot 2026-03-17 at 4 20 38 PM

PR Checklist

  • npm run lint passes
  • Inline reference is included / updated (not applicable – bug fix only)
  • Unit tests are included / updated

@welcome
Copy link
Copy Markdown

welcome bot commented Feb 22, 2026

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

@davepagurek
Copy link
Copy Markdown
Contributor

Thanks for working on this! As this is into the main branch, we'll want another PR after this making similar changes into the dev-2.0 branch, where p5 2.x is developed. The code looks like it could largely be the same (but you'll likely want to manually change it on the new base because so much has changed between the branches, merging/rebasing won't be easy), and also how mocking works in tests is a little different as 2.x switched to using vitest.


test('TESS mode skips prompt when p5.disableFriendlyErrors is true', function(done) {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);
var confirmStub = sinon.stub(window, 'confirm').returns(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like tests are currently failing here:

   2) Graphics
       p5.Graphics.resizeCanvas
         Rendering
           p5.prototype.resizeCanvas
             p5.Framebuffer
               sizing
                 p5.RendererGL
                   beginShape() in WEBGL mode
                     TESS mode skips prompt when p5.disableFriendlyErrors is true:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Does this test also take a while locally?

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.

Browser freeze when creating >65k vertices in draw() loop (no validation or warning)

2 participants