@@ -50,25 +50,21 @@ var defaultId = 'defaultCanvas0'; // this gets set again in createCanvas
5050p5 . 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
0 commit comments