Skip to content

Fix #8575: Correct builtin global accessors in p5.strands instance mode#8600

Closed
saurabh24thakur wants to merge 4 commits intoprocessing:dev-2.0from
saurabh24thakur:issue-8575
Closed

Fix #8575: Correct builtin global accessors in p5.strands instance mode#8600
saurabh24thakur wants to merge 4 commits intoprocessing:dev-2.0from
saurabh24thakur:issue-8575

Conversation

@saurabh24thakur
Copy link

Resolves #8575

Changes

  • Fixed Instance Mode Accessors: Built-in globals (like mouseX, width, height, deltaTime) are now correctly installed on the p5 instance and Graphics.prototype, ensuring they are recognized as StrandsNode objects in instance mode.
  • Infinite Recursion Safety: Wrapped accessors to use original property descriptors where available, resolving stack overflow errors when accessing properties that p5 updates internally.
  • Implemented Setters: Added setters to the Strands accessors to support p5's internal variable shadowing (e.g., this.deltaTime = ...), maintaining compatibility with p5's frame timing logic.
  • Enhanced Unit Tests: Updated test/unit/webgl/p5.Shader.js to verify global accessor behavior in both global and instance modes.

Screenshots of the change

Manual verification confirmed: ✅ SUCCESS: p.mouseX is a StrandsNode! and resolved previous console errors (Maximum call stack size exceeded and TypeError: Cannot set property deltaTime).

PR Checklist

  • npm run lint passes
  • [Inline reference] is included / updated
  • [Unit tests] are included / updated

…rrors, and FES mocking in browser environment
Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I think the implementation is more complicated than I would expect it to be, would you mind explaining a bit if you tried passing in fn and p5.Graphics.prototype and what issues that ran into?

Also what was the issue with infinite looping? Do you have a test sketch where that was happening in v2.2.2?

});
const id = DAG.getOrCreateNode(dag, nodeData);
CFG.recordInBasicBlock(cfg, cfg.currentBlock, id);
return { id, dimension: properties.length, components: structTypeInfo.components };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was this part fixing?

// Find the original descriptor if it exists on this target or its prototype chain
let originalDescriptor = null;
let curr = target;
while (curr && !originalDescriptor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain a bit why this while loop was necessary? Was p5.Graphics.prototype or fn not working correctly?

…or components

Summary of changes:
- Simplified installBuiltinGlobalAccessors by removing prototype chain loop.
- Moved accessor installation to initGlobalStrandsAPI for earlier availability.
- Fixed invalid reference to structTypeInfo.components in ir_builders.js and added clarifying comment.
- Added unit test in p5.Shader.js to verify mouseX getter on p5.prototype.
@saurabh24thakur
Copy link
Author

@davepagurek I have fix those too ..Let verify my PR..

@ksen0
Copy link
Member

ksen0 commented Mar 3, 2026

Hi @saurabh24thakur. Thanks for your time and effort on this. I've reviewed the updates and unfortunately there are still quite some puzzling parts in the code, making surprising changes that are not clear from original issue scope. You also have not answered @davepagurek's requests for explanations. Engaging constructively in discussion is a very important part of open source. To avoid blocking the project, I’m going to unassign this work for now, and open this to other volunteers. Thanks so much for your understanding. If you would like to work on either this or another task, please be sure to understand the issue more deeply and to engage with maintainers and stewards reviews.

@ksen0 ksen0 closed this Mar 3, 2026
@saurabh24thakur
Copy link
Author

saurabh24thakur commented Mar 4, 2026

I completely understand the decision to unassign me, and I apologize for not engaging constructively with your questions earlier. I was over-complicating the solution to handle recursion issues I hit during testing, but I realize now that my lack of explanation made the code difficult to review.

I have since gone back to the basics and simplified the logic to focus strictly on passing p5.prototype and p5.Graphics.prototype as targets, as @davepagurek suggested. I would appreciate one more chance to tackle this issue; I am committed to discussing the implementation here in the comments before opening a new PR to ensure it aligns with the project's standards..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants