Skip to content

Commit 2e28bc5

Browse files
committed
Add comments to explain logic
1 parent 665ec27 commit 2e28bc5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,21 +940,25 @@ class RendererGL extends Renderer {
940940
};
941941

942942
if (isPGraphics) {
943+
// Handle PGraphics: remove and recreate the canvas
943944
const pg = this._pInst;
944945
pg.canvas.parentNode.removeChild(pg.canvas);
945946
pg.canvas = document.createElement("canvas");
946947
const node = pg._pInst._userNode || document.body;
947948
node.appendChild(pg.canvas);
948949
Element.call(pg, pg.canvas, pg._pInst);
950+
// Restore previous width and height
949951
pg.width = w;
950952
pg.height = h;
951953
} else {
954+
// Handle main canvas: remove and recreate it
952955
let c = this.canvas;
953956
if (c) {
954957
c.parentNode.removeChild(c);
955958
}
956959
c = document.createElement("canvas");
957960
c.id = defaultId;
961+
// Attach the new canvas to the correct parent node
958962
if (this._pInst._userNode) {
959963
this._pInst._userNode.appendChild(c);
960964
} else {

0 commit comments

Comments
 (0)