Fix filter() crash on createGraphics(WEBGL) by mirroring strands API … by aashu2006 · Pull Request #8568 · processing/p5.js

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