Skip to content

Fix duplicate p5.js init by checking window.p5 and skipping if alread… #7791

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

Open
wants to merge 1 commit into
base: dev-2.0
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ class p5 {
// 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) {
if (window.p5 instanceof p5) {
console.warn('p5.js appears to have been imported multiple times. This could cause errors.');
return;
}
this._isGlobal = true;
window.p5 = this;
if (window.hitCriticalError) {
return;
}
Expand Down