Skip to content

Commit 2bb7aa5

Browse files
author
Lauren McCarthy
committed
removing canvas on webgl creation closes 2241
1 parent e012ba3 commit 2bb7aa5

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/core/rendering.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,21 @@ var defaultId = 'defaultCanvas0'; // this gets set again in createCanvas
5050
p5.prototype.createCanvas = function(w, h, renderer) {
5151
//optional: renderer, otherwise defaults to p2d
5252
var r = renderer || constants.P2D;
53-
var isDefault, c;
54-
55-
//4th arg (isDefault) used when called onLoad,
56-
//otherwise hidden to the public api
57-
if(arguments[3]){
58-
isDefault =
59-
(typeof arguments[3] === 'boolean') ? arguments[3] : false;
60-
}
53+
var c;
6154

6255
if(r === constants.WEBGL){
6356
c = document.getElementById(defaultId);
64-
if(c){ //if defaultCanvas already exists
57+
if(c) { //if defaultCanvas already exists
6558
c.parentNode.removeChild(c); //replace the existing defaultCanvas
59+
this._elements = this._elements.filter(function(e) {
60+
return e !== this._renderer;
61+
});
6662
}
6763
c = document.createElement('canvas');
6864
c.id = defaultId;
6965
}
7066
else {
71-
if (isDefault) {
67+
if (!this._defaultGraphicsCreated) {
7268
c = document.createElement('canvas');
7369
var i = 0;
7470
while (document.getElementById('defaultCanvas'+i)) {
@@ -94,25 +90,22 @@ p5.prototype.createCanvas = function(w, h, renderer) {
9490
}
9591

9692

97-
9893
// Init our graphics renderer
9994
//webgl mode
10095
if (r === constants.WEBGL) {
10196
this._setProperty('_renderer', new p5.RendererGL(c, this, true));
102-
this._isdefaultGraphics = true;
97+
this._elements.push(this._renderer);
10398
}
10499
//P2D mode
105100
else {
106-
if (!this._isdefaultGraphics) {
101+
if (!this._defaultGraphicsCreated) {
107102
this._setProperty('_renderer', new p5.Renderer2D(c, this, true));
108-
this._isdefaultGraphics = true;
103+
this._defaultGraphicsCreated = true;
104+
this._elements.push(this._renderer);
109105
}
110106
}
111107
this._renderer.resize(w, h);
112108
this._renderer._applyDefaults();
113-
if (isDefault) { // only push once
114-
this._elements.push(this._renderer);
115-
}
116109
return this._renderer;
117110
};
118111

src/webgl/p5.RendererGL.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ p5.RendererGL.prototype._resetContext = function(attr, options, callback) {
168168
this._pInst.canvas = c;
169169
this._pInst._setProperty('_renderer', new p5.RendererGL(this._pInst.canvas,
170170
this._pInst, true, attr));
171-
this._pInst._isdefaultGraphics = true;
172171
this._pInst._renderer.resize(w, h);
173172
this._pInst._renderer._applyDefaults();
174173
this._pInst._elements.push(this._renderer);

0 commit comments

Comments
 (0)