@@ -167,6 +167,7 @@ class p5 {
167
167
//////////////////////////////////////////////
168
168
169
169
this . _setupDone = false ;
170
+ this . _preloadDone = false ;
170
171
// for handling hidpi
171
172
this . _pixelDensity = Math . ceil ( window . devicePixelRatio ) || 1 ;
172
173
this . _userNode = node ;
@@ -292,7 +293,7 @@ class p5 {
292
293
293
294
this . _decrementPreload = function ( ) {
294
295
const context = this . _isGlobal ? window : this ;
295
- if ( typeof context . preload === 'function' ) {
296
+ if ( ! context . _preloadDone && typeof context . preload === 'function' ) {
296
297
context . _setProperty ( '_preloadCount' , context . _preloadCount - 1 ) ;
297
298
context . _runIfPreloadsAreDone ( ) ;
298
299
}
@@ -309,6 +310,8 @@ class p5 {
309
310
310
311
this . _incrementPreload = function ( ) {
311
312
const context = this . _isGlobal ? window : this ;
313
+ // Do nothing if we tried to increment preloads outside of `preload`
314
+ if ( context . _preloadDone ) return ;
312
315
context . _setProperty ( '_preloadCount' , context . _preloadCount + 1 ) ;
313
316
} ;
314
317
@@ -336,6 +339,8 @@ class p5 {
336
339
// Record the time when sketch starts
337
340
this . _millisStart = window . performance . now ( ) ;
338
341
342
+ context . _preloadDone = true ;
343
+
339
344
// Short-circuit on this, in case someone used the library in "global"
340
345
// mode earlier
341
346
if ( typeof context . setup === 'function' ) {
0 commit comments