Tokenmagic icon indicating copy to clipboard operation
Tokenmagic copied to clipboard

[BUG] FilterSprite without texture can break canvas drawing

Open gludington opened this issue 1 year ago • 1 comments

Module Version: v0.6.9 Foundry Version: 12.331

Describe the bug Creating a filter type of sprite on a token that already has an effect applied breaks canvas drawing

** Expected Behavior ** The canvas continues to draw

** Actual Behavior ** The canvas breaks and can no longer draw.

To Reproduce Steps to reproduce the behavior:

  1. Create a world. I used D&D 4.1.2, but system should not matter
  2. Create a scene, and an actor. Content not necessary -- will happen with a blank scene and the mystery man token await TokenMagic.addUpdateFiltersOnSelected(params);`
  3. Activate TokenMagicFX module
  4. From TokenMagic portfolio, add the Glow effect onto the token
  5. Create this script macro let params = [ { "filterType": "sprite", "filterId": "base-terrain", "animated": { "translationX": { "active": false, "speed": -0.0000012, "animType": "move", } } } ]; await TokenMagic.addUpdateFiltersOnSelected(params);
  6. Select the now glowing token
  7. Invoke the macro
  8. The canvas breaks, with this in the console

Uncaught TypeError: Cannot read properties of undefined (reading '_texture') [Detected 1 package: tokenmagic(0.6.9)] at ey.apply (FilterSprite.js:354:28) at ey.apply (FilterProto.js:103:16) at en.pop (FilterSystem.ts:368:24) at PrimarySpriteMesh.renderAdvanced (Container.ts:751:29) at PrimarySpriteMesh.render (Container.ts:661:18) at PrimaryCanvasGroup.renderAdvanced (Container.ts:735:34) at PrimaryCanvasGroup.render (Container.ts:661:18) at PrimaryCanvasGroup.render (foundry.js:28550:13) at EnvironmentCanvasGroup.render (Container.ts:673:34) at RenderedCanvasGroup.render (Container.ts:673:34) at ia.renderAdvanced (Container.ts:735:34) at ia.render (Container.ts:661:18)t at xn.render (ObjectRendererSystem.ts:104:23) at ea.render (Renderer.ts:377:29) at na.render (Application.ts:90:23) at mn.emit (TickerListener.ts:67:25) at Pt.update (Ticker.ts:427:37) at Pt._tick (Ticker.ts:129:22)

Line: https://github.com/Feu-Secret/Tokenmagic/blob/master/tokenmagic/fx/filters/FilterSprite.js#L354 It appears that this combination results in a FilterSprite without a texture, so that this.targetSprite is undefined.

A defensive guard at this point resolves the issue and allows the canvas to draw - I will create a PR - but somewhere deeper this sort of creation should probably be addressed or disallowed.

gludington avatar Dec 30 '24 03:12 gludington

Stepping through the debugger, the texture is not assigned because there is not an imagePath in the initial params, as per https://github.com/Feu-Secret/Tokenmagic/blob/master/tokenmagic/fx/filters/FilterSprite.js#L93

With even an not-found imagePath, the canvas does not break.

Perhaps a defensive guard in apply, but also setting a fundamentally invalid texture if an imagePath is missing?

gludington avatar Dec 30 '24 04:12 gludington