Skip to content

Fix _isGlobal flag in ini method #7785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/core/main.js
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ class p5 {
//////////////////////////////////////////////
// PUBLIC p5 PROPERTIES AND METHODS
//////////////////////////////////////////////

this._isGlobal = !sketch;
/**
* A function that's called once to load assets before the sketch runs.
*
@@ -286,7 +286,6 @@ class p5 {
this._glAttributes = null;
this._requestAnimId = 0;
this._preloadCount = 0;
this._isGlobal = false;
this._loop = true;
this._startListener = null;
this._initializeInstanceVariables();
@@ -661,21 +660,11 @@ class p5 {
// ensure correct reporting of window dimensions
this._updateWindowSize();

// call any registered init functions
this._registeredMethods.init.forEach(function(f) {
if (typeof f !== 'undefined') {
f.call(this);
}
}, this);
// Set up promise preloads
this._setupPromisePreloads();

const friendlyBindGlobal = this._createFriendlyGlobalFunctionBinder();

// If the user has created a global setup or draw function,
// assume "global" mode and make everything global (i.e. on the window)
if (!sketch) {
this._isGlobal = true;
if (this._isGlobal) {
p5.instance = this;
// Loop through methods on the prototype and attach them to the window
for (const p in p5.prototype) {
@@ -710,8 +699,14 @@ class p5 {
p5._checkForUserDefinedFunctions(this);
}

// Bind events to window (not using container div bc key events don't work)
this._updateWindowSize();

// call any registered init functions
this.callRegisteredHooksFor('init');
// Set up promise preloads
this._setupPromisePreloads();

// Bind events to window (not using container div bc key events don't work)
for (const e in this._events) {
const f = this[`_on${e}`];
if (f) {