File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,18 @@ class Element {
63
63
}
64
64
}
65
65
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
+
68
78
if ( sketch && ! sketch . _elements && sketch . _pInst ) {
69
79
sketch = sketch . _pInst ; // climb one level up
70
80
}
You can’t perform that action at this time.
0 commit comments