Skip to content

Commit 455168c

Browse files
committed
Fix _isgloabl flag in ini method
1 parent 57fbaae commit 455168c

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/core/main.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class p5 {
3737
//////////////////////////////////////////////
3838
// PUBLIC p5 PROPERTIES AND METHODS
3939
//////////////////////////////////////////////
40-
40+
const hasGlobalSetupOrDraw = typeof window.setup === 'function' || typeof window.draw === 'function';
41+
this._isGlobal = !sketch || hasGlobalSetupOrDraw;
4142
/**
4243
* A function that's called once to load assets before the sketch runs.
4344
*
@@ -286,7 +287,6 @@ class p5 {
286287
this._glAttributes = null;
287288
this._requestAnimId = 0;
288289
this._preloadCount = 0;
289-
this._isGlobal = false;
290290
this._loop = true;
291291
this._startListener = null;
292292
this._initializeInstanceVariables();
@@ -661,21 +661,14 @@ class p5 {
661661
// ensure correct reporting of window dimensions
662662
this._updateWindowSize();
663663

664-
// call any registered init functions
665-
this._registeredMethods.init.forEach(function(f) {
666-
if (typeof f !== 'undefined') {
667-
f.call(this);
668-
}
669-
}, this);
670664
// Set up promise preloads
671665
this._setupPromisePreloads();
672666

673667
const friendlyBindGlobal = this._createFriendlyGlobalFunctionBinder();
674668

675669
// If the user has created a global setup or draw function,
676670
// assume "global" mode and make everything global (i.e. on the window)
677-
if (!sketch) {
678-
this._isGlobal = true;
671+
if (this._isGlobal) {
679672
p5.instance = this;
680673
// Loop through methods on the prototype and attach them to the window
681674
for (const p in p5.prototype) {
@@ -710,6 +703,8 @@ class p5 {
710703
p5._checkForUserDefinedFunctions(this);
711704
}
712705

706+
// call any registered init functions
707+
this.callRegisteredHooksFor('init');
713708
// Bind events to window (not using container div bc key events don't work)
714709

715710
for (const e in this._events) {

0 commit comments

Comments
 (0)