dev7355608 / vision-5e

Foundry VTT Module: Vision/Detection Modes for D&D 5e
https://foundryvtt.com/packages/vision-5e
MIT License
13 stars 12 forks source link

[BUG - 2.5.0]: The detectionModes sorting triggers errors for all Token5e placed on a scene, when placing a new Token on the scene. #107

Closed thatlonelybugbear closed 2 months ago

thatlonelybugbear commented 2 months ago
foundry.js:655 
 Error: Failed data preparation for Scene.GDn5FWPqQtbVK8IP.Token.fo02RVjtjiY38Xh8. Cannot read properties of undefined (reading 'important')
[Detected 2 packages: vision-5e(2.5.0), system:dnd5e(3.3.1)]
    at Hooks.onError (foundry.js:654:24)
    at 🎁Hooks.onError#0 (libWrapper-wrapper.js:188:54)
    at TokenDocument5e._safePrepareData (foundry.js:10801:15)
    at Scene.prepareEmbeddedDocuments (foundry.js:10845:13)
    at Scene.prepareData (foundry.js:10822:12)
    at Scene._safePrepareData (foundry.js:10799:14)
    at Scene._initialize (foundry.js:10630:19)
    at Scene.reset (foundry.js:21396:10)
    at #handleCreateDocuments (foundry-esm.js:56444:15)
    at async Function.createDocuments (foundry-esm.js:11423:23)
    at async Function.create (foundry-esm.js:11567:23)
Caused by: TypeError: Cannot read properties of undefined (reading 'important')
[Detected 2 packages: vision-5e(2.5.0), system:dnd5e(3.3.1)]
    at token-document.mjs:16:52

Seems that a small check to make sure that the a is no empty fixes this, but unsure if that is the best way to do.

this.detectionModes.sort((a, b) => {
  a = CONFIG.Canvas.detectionModes[a.id];
  b = CONFIG.Canvas.detectionModes[b.id];
  if (!foundry.utils.isEmpty(a))
    return (b.important ?? false) - (a.important ?? false)
      || (a.imprecise ?? false) - (b.imprecise ?? false)
      || (b.id === this.sight.detectionMode) - (a.id === this.sight.detectionMode)
      || (b.priority ?? 0) - (a.priority ?? 0);
});
dev7355608 commented 2 months ago

I suspect this is caused by #105: the error probably messed up the initialization of Vision 5e's detection modes entirely.

thatlonelybugbear commented 2 months ago

Ah possibly. I'll go grab the 2.5.1!

thatlonelybugbear commented 2 months ago

Seems all good on 2.5.1!

Thanks :)