Fix build*Shader methods in instance mode by forwarding optional scope by aashu2006 · Pull Request #8523 · processing/p5.js
Resolves #8520
Changes
The five build*Shader methods in src/webgl/material.js were calling .modify(callback) without forwarding the optional scope parameter.
In instance mode, users pass { p5 } or { sketch } as scope so the callback receives the correct instance. Since this argument was not forwarded, the callback didn’t receive the expected context.
This PR updates these methods to accept an optional scope parameter and pass it to .modify(callback, scope)
No changes are made to .modify() itself, and existing code without scope continues to work.
I have also added a unit test under test/unit/webgl/p5.Shader.js (inside the existing p5.strands suite) to verify that buildMaterialShader correctly forwards the optional scope to .modify(). JSDoc comments were updated to document the optional scope parameter.
// Before fn.buildFilterShader = function (callback) { return this.baseFilterShader().modify(callback); }; // After fn.buildFilterShader = function (callback, scope) { return this.baseFilterShader().modify(callback, scope); };
PR Checklist
-
npm run lintpasses - Inline reference is included / updated
- Unit tests are included / updated