Skip to content

Commit 63cc5a0

Browse files
authored
Fixing suggestions from kit
1 parent 3933911 commit 63cc5a0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/dom/p5.Element.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ class Element {
6363
}
6464
}
6565

66-
// delete the reference in this._pInst._elements
67-
let sketch = this._pInst;
66+
// `this._pInst` is usually the p5 “sketch” object that owns the global
67+
// `_elements` array. But when an element lives inside an off-screen
68+
// `p5.Graphics` layer, `this._pInst` is that wrapper Graphics object
69+
// instead. The wrapper keeps a back–pointer (`_pInst`) to the real
70+
// sketch but has no `_elements` array of its own.
71+
72+
let sketch = this._pInst;
73+
74+
// If `sketch` doesn’t own an `_elements` array it means
75+
// we’re still at the graphics-layer “wrapper”.
76+
// Jump one level up to the real p5 sketch stored in sketch._pInst.
77+
6878
if (sketch && !sketch._elements && sketch._pInst) {
6979
sketch = sketch._pInst; // climb one level up
7080
}

0 commit comments

Comments
 (0)