Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing suggestions from kit
  • Loading branch information
perminder-17 authored May 26, 2025
commit 63cc5a0f8ade19bf4efad0dfd906028cd0df41dc
14 changes: 12 additions & 2 deletions src/dom/p5.Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,18 @@ class Element {
}
}

// delete the reference in this._pInst._elements
let sketch = this._pInst;
// `this._pInst` is usually the p5 “sketch” object that owns the global
// `_elements` array. But when an element lives inside an off-screen
// `p5.Graphics` layer, `this._pInst` is that wrapper Graphics object
// instead. The wrapper keeps a back–pointer (`_pInst`) to the real
// sketch but has no `_elements` array of its own.

let sketch = this._pInst;

// If `sketch` doesn’t own an `_elements` array it means
// we’re still at the graphics-layer “wrapper”.
// Jump one level up to the real p5 sketch stored in sketch._pInst.

if (sketch && !sketch._elements && sketch._pInst) {
Copy link
Member

Choose a reason for hiding this comment

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

I think a little more inline docs could be useful here to explain the logic

sketch = sketch._pInst; // climb one level up
}
Expand Down