Repository navigation
Conversation
Journal each temporary install on window, p5.prototype and p5.Graphics.prototype with its previous property descriptor, and restore the journal newest first after the build. Absent properties are removed again and setters never run. A property that can be neither redefined nor assigned is rejected before it is written, and a failed restore never replaces a build's own error. This also restores options.hook properties onto p5.Graphics.prototype rather than p5.Graphics, and a modify() called from inside another build's callback hands the enclosing journal back. Part of processing#9259.
Add p5.registerStrandsState(name, { init, update, read }), which returns
a factory for helpers used inside hooks. Helper state is merged across
if/else branches and carried through for loops, and
pushStrandsState()/popStrandsState() save and restore every helper's
scoped fields.
Uses that cannot work throw clear errors: a helper used outside the hook
call that created it, created inside a branch or loop, or used in a loop
header; break or early return in a loop body while helpers exist;
updates inside ?:, &&, ||, &&= or ||= operands; changing a state's
shape; and unbalanced push/pop.
The addon API is documented in contributor_docs/p5.strands.md.
Part of processing#9259.
If a hook throws and sketch code catches the error inside modify(), the first failure is rethrown as soon as the callback returns, before code generation. The helper scope is cleared so the next build starts clean, and finishHook's "requires a value" check now runs inside the same cleanup. The contributor doc notes this behaviour. Part of processing#9259.
A base shader can pass globalInstance next to hook in modify()'s options. It is called after that hook's begin() with the sketch as `this`, and the helper it returns has its methods installed with _installGlobal() on window, p5.prototype and p5.Graphics.prototype for the rest of the build, through the temporary install journal. The contributor doc covers options.hook, globalInstance, _installGlobal() and the temporary replacement and restoration of names. Part of processing#9259.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #9259
Changes:
This lets addons create Strands helpers that keep track of their shader values through
if/elsebranches andforloops, rather than having to manage that state themselves.p5.registerStrandsState()returns a factory for independent helpers with read and update methods. Helpers can keep scoped values thatpushStrandsState()andpopStrandsState()restore, alongside global values that stay updated.The optional
globalInstanceoption lets an addon expose one helper’s methods for the duration of a build. This reuses the temporary-property cleanup, which now restores the original properties after both successful and failed builds.As discussed in the issue, caught errors from hook callbacks or
begin()/end()stop the build before code generation and preserve the original thrown value. Errors caught between manualbegin()andend()calls are outside that protection.Addon documentation and two runnable examples are included in
contributor_docs/p5.strands.md.Tested locally:
Screenshots of the change:
No UI changes. The tests check rendered pixels on WebGL and WebGPU.
PR Checklist
npm run lintpassesAI disclosure: AI tools were used for tests and documentation. I reviewed and approved the decisions, and tested the changes locally.