Skip to content

Skip MeasuredTemplate placeables whose _draw left them incomplete#313

Open
takaqiao wants to merge 1 commit into
Feu-Secret:masterfrom
takaqiao:fix/v14-broken-template-guards
Open

Skip MeasuredTemplate placeables whose _draw left them incomplete#313
takaqiao wants to merge 1 commit into
Feu-Secret:masterfrom
takaqiao:fix/v14-broken-template-guards

Conversation

@takaqiao
Copy link
Copy Markdown

@takaqiao takaqiao commented May 5, 2026

Summary

A MeasuredTemplate placeable can survive into canvasReady without this.template (its PIXI.Graphics) or a registered highlight layer:

  • loadTexture rejects on a missing/failing fill texture and _draw aborts before this.template = this.addChild(new PIXI.Graphics()).
  • The system migrated spell areas off MeasuredTemplate — PF2e v8 places Region documents instead, but legacy MeasuredTemplate documents from older PF2e versions are still present in scene data.
  • The placeable was created in a state where the canvas hadn't finished initializing.

The bundle currently dereferences both unconditionally and throws on those.

Repro

Foundry v14 + PF2e v8 world with any legacy MeasuredTemplate documents in a scene. On scene activation:

Error thrown in hooked function '' for hook 'canvasReady'.
Cannot set properties of undefined (setting 'alpha')
  at d (tokenmagic.js:859:70)
  at Object._loadFilters (tokenmagic.js:848:6)
  at Object.fn (tokenmagic.js:1762:8)

And then on every pointer move once defaultTemplateOnHover is on:

Uncaught TypeError: Cannot set properties of undefined (setting 'alpha')
  at ia.<anonymous> (settings.js:425:25)

Changes

  • _singleLoadFilters (module/tokenmagic.js): for the TEMPLATE branch, fetch _TMFXgetSprite() once and skip the alpha/tint assignments when it returns null/undefined. The REGION branch already guarded its sprite this way; this brings the template branch in line.
  • defaultTemplateOnHover mousemove handler (module/settings.js): continue past templates whose template.template is missing, and past templates whose grid highlight layer didn't get registered (the previous expression hl.renderable = … crashed otherwise).

No behavioural change for templates that drew successfully — broken templates are simply skipped instead of taking down the canvasReady chain or the pointermove pipeline.

Test plan

  • Foundry v13 (verified): templates with valid textures still get their filters loaded and their hover dimming applied.
  • Foundry v14 + PF2e v8 with a scene containing legacy MeasuredTemplate documents: canvasReady completes without throwing, pointer moves don't spam errors, and any healthy templates in the same scene still behave normally.
  • Re-create / re-draw a template at runtime and confirm filters apply once _draw finishes.

A MeasuredTemplate placeable can survive into canvasReady without
this.template (the PIXI.Graphics) or a registered highlight layer:
loadTexture rejects on a missing/failing fill, the system migrated
spell areas off MeasuredTemplate (PF2e v8 places Regions instead, but
legacy scene documents remain), or the placeable was created before
the canvas finished initializing.

The bundle currently dereferences both unconditionally:

- _singleLoadFilters does
    placeable.document.tmfxTextureAlpha = placeable._TMFXgetSprite().alpha = updateData.opacity;
  which throws TypeError 'Cannot set properties of undefined' when
  _TMFXgetSprite() returns undefined for a TEMPLATE whose this.template
  was never assigned.

- The defaultTemplateOnHover mousemove handler does
    hl.renderable = ...; template.template.alpha = ...;
  and crashes hundreds of times per second on a hover when either is
  missing.

Both reproduce on Foundry v14 + PF2e v8 worlds with leftover legacy
MeasuredTemplate documents.

Skip the broken placeables instead of dereferencing through undefined.
The Region branch already guarded its sprite this way; this brings
TEMPLATE and the hover handler in line.
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.

1 participant