fix: prevent browser freeze when tessellating >50k vertices (dev-2.0)#8729
fix: prevent browser freeze when tessellating >50k vertices (dev-2.0)#8729Nixxx19 wants to merge 4 commits intoprocessing:dev-2.0from
Conversation
Continuous ReleaseCDN linkPublished PackagesCommit hash: 746e46c Previous deploymentsThis is an automated message. |
| const MAX_SAFE_TESSELLATION_VERTICES = 50000; | ||
|
|
||
| if (vertexCount > MAX_SAFE_TESSELLATION_VERTICES) { | ||
| const p5Class = this.renderer._pInst.constructor; |
There was a problem hiding this comment.
Ah yes this is one of the currently kinda awkward bits of 2.x now that we've split core functionality into addons: there is not always a global p5. The way we're currently dealing with this is with a sort of "dependency injection" pattern of sorts, where we make a function on the current class, like in this case maybe friendlyErrorsDisabled() { return false; }, and then in an addon file inside of function myAddon(p5, fn, lifecycles) { ... }, we override that function with a real implementation. Take a look in this PR at how we've given p5.Image access to p5.friendlyError: https://github.com/processing/p5.js/pull/8676/changes#diff-fdf1c89a0511ed981f59e9539de1ff707da1e75c7b21f35184406cacb5781672
Let's maybe try to follow a similar pattern here where we override ShapeBuilder.friendlyErrorsDisabled (or whatever we choose to call it) from within the addon function that adds the WebGL renderer to p5?
There was a problem hiding this comment.
thanks for the pointer! yeah that pattern makes way more sense, the _pInst.constructor thing was definitely awkward. added a friendlyErrorsDisabled() on ShapeBuilder that returns false by default, and then overrode it inside the renderer3D addon where p5 is in scope to actually check p5.disableFriendlyErrors. tests still pass. let me know if you had something slightly different in mind!

Resolves #8219 for the dev-2.0 branch
This is the dev-2.0 port of #8555.
Summary
libtess._largeTessellationAcknowledgedand tessellates normally without prompting again.p5.disableFriendlyErrors: when disabled, tessellation always runs with no prompt.Tests
Added unit tests in
test/unit/webgl/p5.RendererGL.jsunder thebeginShape() in WEBGL modesuite, written in vitest syntax (vi.spyOn/mockImplementation). All 4 tests pass locally.