Skip to content

fix: run canvas teardown in Renderer3D.remove() - #9162

Open
Vaivaswat2244 wants to merge 1 commit into
processing:mainfrom
Vaivaswat2244:fix/renderer3d-duplicate-remove
Open

fix: run canvas teardown in Renderer3D.remove()#9162
Vaivaswat2244 wants to merge 1 commit into
processing:mainfrom
Vaivaswat2244:fix/renderer3d-duplicate-remove

Conversation

@Vaivaswat2244

Copy link
Copy Markdown
Contributor

Split out of #9103 at review, where it was flagged as a refactor that did not belong in a lint cleanup.

Changes:

Renderer3D declares remove() twice, at L440 and L2175. A class body is evaluated top to bottom, so the second definition overwrites the first and Renderer3D.prototype.remove has only ever been the later one. The overwritten method is the canvas teardown, identical to Renderer2D.remove(). It stopped running when the second remove() was added for _textCanvas cleanup in ef28cbc.

This shows up as a 2D/3D asymmetry at two call sites:

  • p5.Graphics.remove() calls _renderer.remove() and nothing else, so createGraphics(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 detaches e.elt for everything in _elements regardless.

The fix deletes the overwritten declaration and folds its body into the surviving one, after the _textCanvas block (which reads parentElement, so it has to run before canvas and elt are nulled). super.remove() is a no-op in the base class so its position is unchanged.

This makes remove() non-idempotent in the same way Renderer2D.remove() already is: a second call throws on this.wrappedElt.remove(). Happy to guard it if preferred.

Screenshots of the change:

N/A

PR Checklist

  • npm run lint passes
  • Inline reference is included / updated (N/A, no public API changes)
  • Unit tests are included / updated (existing suites pass: 2174 passed, 0 failed)

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().
@p5-bot

p5-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: ce17599

Previous deployments

This is an automated message.

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