-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
@Spongman highlights in #3155 that there is a confusion between the properties .elt and .canvas causing us to write defensive code like so:
p5.js/src/core/p5.Renderer2D.js
Line 112 in 5a46133
| cnv = img.canvas || img.elt; |
What is the purpose of having both .elt and .canvas? How can it be that the canvas should sometimes come from .elt and sometimes from .canvas?
Searching for .canvas = I get these results:
Line 2637 in 5a46133
| this.canvas = document.createElement('canvas'); |
Line 29 in 5a46133
| this.canvas = document.createElement('canvas'); |
Line 26 in 5a46133
| this.canvas = elt; |
Line 144 in 5a46133
| this.canvas = document.createElement('canvas'); |
p5.js/src/webgl/p5.RendererGL.js
Line 176 in 5a46133
| this._pInst.canvas = c; |
Searching for
.elt = I get these results:Line 44 in 5a46133
| this.elt = elt; |
Line 585 in 5a46133
| elt = this.elt = arg.elt; |
Line 723 in 5a46133
| elt = this.elt = existing_radios.elt; |
and a comment about checking if the canvas is associated with the p5 instance
Lines 1938 to 1939 in 5a46133
| // main canvas associated with p5 instance | |
| if (this._pInst._curElement.elt === this.elt) { |
Some of the places that assign canvas also assign elt afterwards, some do not.
In #3155 @Spongman solves the problem via if (!this.canvas) this.loadPixels();, is that a general approach we should apply elsewhere?
Do we have a place where we can add (or already have?) YUIDocs for .elt and .canvas?
Metadata
Metadata
Assignees
Type
Projects
Status