Skip to content

Commit 52bd064

Browse files
committed
Fix duplicate p5.js init by checking window.p5 and skipping if already loaded
1 parent 55ed78e commit 52bd064

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/core/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ class p5 {
125125
// If the user has created a global setup or draw function,
126126
// assume "global" mode and make everything global (i.e. on the window)
127127
if (!sketch) {
128+
if (window.p5 instanceof p5) {
129+
console.warn('p5.js appears to have been imported multiple times. This could cause errors.');
130+
return;
131+
}
128132
this._isGlobal = true;
133+
window.p5 = this;
129134
if (window.hitCriticalError) {
130135
return;
131136
}

0 commit comments

Comments
 (0)