-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
_isGlobal is false when it should be true #7781
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
Comments
Hi @quinton-ashley, |
@VANSH3104 I'd suggest only moving the proper initialization of What is your proposed solution and changes? You didn't link to anything in your comment. |
@quinton-ashley Here's what I was thinking — it's not a perfect solution, but I opened the PR to demonstrate the idea and get your feedback.
This passes the p5 instance as this, but it doesn't account for global mode, which causes issues for addons relying on the correct context during init. To fix this, I moved the initialization of this._isGlobal = !sketch to the top of the p5 constructor—before the init hooks run—so that any addon methods depending on _isGlobal get the correct value. I also replaced the manual forEach loop with a call to callRegisteredHooksFor('init'), which handles context switching correctly (window in global mode, this in instance mode). This ensures consistent and expected behavior for addon init methods. |
Added some review comments in the PR @VANSH3104 , thanks for working on this. Thanks for digging into this and sharing your thoughts! Just a quick note for context—in general, we ask that contributors hold off on making PRs before there is maintainer approval of the fix. Once an issue is ready for work, look for the "Ready for Work" as a signal that it's good to proceed! |
@ksen0 Apologies for jumping ahead. I completely forgot about the contribution guidelines. I’ll make sure to wait for maintainer approval and the "Ready for Work" label before opening a PR next time. |
Most appropriate sub-area of p5.js?
p5.js version
v1.11.5
Web browser and version
any
Operating system
any
Steps to reproduce this
_isGlobal
should be set to true when loading a global instance of p5 but it's always false in "init" addon methods.This seems to have always been an issue in v1, not just in v1.11.5.
The text was updated successfully, but these errors were encountered: