fix: run canvas teardown in Renderer3D.remove() - #9162
Open
Vaivaswat2244 wants to merge 1 commit into
Open
Conversation
Renderer3D declared remove() twice. JS keeps only the last definition, so the first - which detaches the canvas and clears wrappedElt, canvas and elt - has been dead since the second was added for _textCanvas cleanup in ef28cbc. Renderer2D.remove() has the identical body it was meant to mirror. Fold the teardown into the surviving method so WebGL and WebGPU canvases are actually detached on remove().
Continuous ReleaseCDN linkPublished PackagesCommit hash: ce17599 Previous deploymentsThis is an automated message. |
limzykenneth
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #9103 at review, where it was flagged as a refactor that did not belong in a lint cleanup.
Changes:
Renderer3Ddeclaresremove()twice, at L440 and L2175. A class body is evaluated top to bottom, so the second definition overwrites the first andRenderer3D.prototype.removehas only ever been the later one. The overwritten method is the canvas teardown, identical toRenderer2D.remove(). It stopped running when the secondremove()was added for_textCanvascleanup in ef28cbc.This shows up as a 2D/3D asymmetry at two call sites:
p5.Graphics.remove()calls_renderer.remove()and nothing else, socreateGraphics(w, h, WEBGL).remove()leaves its canvas in the DOM. The 2D equivalent does not.createCanvas()called a second time disposes the old renderer the same way, so the old WebGL canvas is orphaned. In 2D it is not.p5.remove()is unaffected since it detachese.eltfor everything in_elementsregardless.The fix deletes the overwritten declaration and folds its body into the surviving one, after the
_textCanvasblock (which readsparentElement, so it has to run beforecanvasandeltare nulled).super.remove()is a no-op in the base class so its position is unchanged.This makes
remove()non-idempotent in the same wayRenderer2D.remove()already is: a second call throws onthis.wrappedElt.remove(). Happy to guard it if preferred.Screenshots of the change:
N/A
PR Checklist
npm run lintpasses