Skip to content

Fix filter() crash on createGraphics(WEBGL) by mirroring strands API …#8568

Open
aashu2006 wants to merge 2 commits intoprocessing:dev-2.0from
aashu2006:fix-graphics-filter-strands
Open

Fix filter() crash on createGraphics(WEBGL) by mirroring strands API …#8568
aashu2006 wants to merge 2 commits intoprocessing:dev-2.0from
aashu2006:fix-graphics-filter-strands

Conversation

@aashu2006
Copy link

Resolves #8549

Changes

Fixes filter() crash when called on createGraphics(WEBGL) buffers.

Strands previously augmented only p5.prototype, but p5.Graphics does not inherit from it. When filter() executed on a p5.Graphics instance, strands callbacks (e.g. getTexture, vec*, dot, etc.) were missing, causing runtime errors.

This PR:

  • Introduces two helpers:
    • augmentFn (permanent, unconditional overwrite)
    • augmentFnTemporary (temporary hook with restoration via graphicsOverrides)
  • Mirrors all permanent strands API augmentations from p5.prototype onto p5.Graphics.prototype
  • Mirrors temporary shader hooks during modify() and restores them in deinitStrandsContext
  • Ensures createGraphics(WEBGL).filter() has access to the full strands API layer
  • Prevents temporary hook leakage after modify() completes

WebGL unit tests and visual tests pass locally. Manual testing confirms the crash is resolved.

Screenshots of the change:

Screenshot from 2026-02-25 21-10-48

Manual test confirming no crash and correct behavior:

  • createGraphics(WEBGL).filter(INVERT) runs without error
  • Temporary hooks are cleaned up after execution

PR Checklist

@aashu2006
Copy link
Author

@ksen0, @davepagurek Thanks for taking a look!

This implements the strands => p5.Graphics.prototype mirroring we discussed in #8549. Permanent strands API functions are mirrored via augmentFn. Temporary shader hooks are mirrored via augmentFnTemporary and cleaned up properly. All tests pass locally (WebGL unit & visual), and manual testing confirms createGraphics(WEBGL).filter() no longer crashes. Let me know if you would like any clarifications or adjustments before merge, happy to refine.

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.

Thanks for taking this on, it generally looks good! I left a comment on how we might be able to refactor a bit because currently it's handling graphicsOverrides a little differently than how it handles fn+fnOverrides and window+windowOverrides.

Then do you think we could also add some visual tests that create a WebGL graphic, run a strands shader on it, then draws the graphic back to the main canvas to take a screenshot? That way we can see if we've missed anything else that's required to get this to work.

@aashu2006
Copy link
Author

Hi @davepagurek, I have addressed the review feedback:

  • Refactored augmentFnTemporary to accept strandsContext directly and assign to strandsContext.graphicsOverrides internally, aligning override handling with fnOverrides and windowOverrides.
  • Added a visual regression test inside the existing filter suite that creates a createGraphics(WEBGL) buffer, runs filter(INVERT), draws it back to the main canvas, and screenshots the result.
  • Confirmed WebGL unit tests and visual tests pass locally.

Let me know if anything else should be adjusted, thanks!

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.

2 participants