p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

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

Open VANSH3104 opened this issue 6 months ago • 3 comments

…y loaded

Resolves #7687

Changes:

  • Add check for window.p5 instanceof p5 before global binding
  • Skip initialization and warn if p5.js was already loaded
  • Avoids errors from Object.defineProperty redefinition
  • Fixes issue where multiple p5.js imports cause failures

Screenshots of the change:

PR Checklist

VANSH3104 avatar May 06 '25 07:05 VANSH3104

Hi @limzykenneth,Sorry for the late response—I’ve been busy with my semester exams. I made some changes to the code based on the previous discussion. Could you please take a look at it?

VANSH3104 avatar May 27 '25 05:05 VANSH3104

Now that I think about it, I'm not sure the idea I had would work as in this case p5 would just detect itself as having already been defined as window.p5 making initialization impossible. @VANSH3104 Have you tested the code here to see if it works?

limzykenneth avatar May 27 '25 10:05 limzykenneth

@limzykenneth Yes, I did test the code, but unfortunately didn’t get the desired result. I think your concern about p5 being already attached to window.p5 and causing initialization issues might actually be what's happening here. I’m still experimenting to better understand the behavior

VANSH3104 avatar May 27 '25 10:05 VANSH3104

Hi @limzykenneth , I tested the changes again and I think the issue is fixed now. Please let me know if you notice anything I might have missed.

VANSH3104 avatar Oct 01 '25 08:10 VANSH3104