teroparvinen / foundry-wire

10 stars 4 forks source link

Avoid crash on actor creation; token item activation #35

Closed TheGiddyLimit closed 1 year ago

TheGiddyLimit commented 1 year ago

Crashes occur on documents which Foundry considers valid.

Reproduction steps:

(async () => {
    const scene = await Scene.create({name: "Test Scene", active: true, padding: 0}, {renderSheet: false})
    await scene.activate()

    // First crash; `module/game/effect-flags.js`
    const actor = await Actor.create({name: "Test", type: "character"});

    await actor.createEmbeddedDocuments("Item", [{name: "Test", type: "feat"}]);

    const tokenName = `${actor.name} (TOKEN)`
    const td = await actor.getTokenDocument({name: tokenName, x: scene.width / 2, y: scene.height / 2})
    const token = await td.constructor.create(td, {parent: canvas.scene})

    // Second crash; `module/item-properties.js`
    token.actor.items.contents[0].use();
})()

Note that this does not fix the class of bugs; there may be similar issues which require similar fixes. These were the two standouts I found during basic use.

teroparvinen commented 1 year ago

The fix seems valid, and this is probably a duplicate of #37. What worries me is that I can't replicate this issue. Is there anything special in your setup, and does this happen if you disable all modules except WIRE, socketlib and libwrapper?

TheGiddyLimit commented 1 year ago

whoops, I did indeed. My fault on both counts; you can most likely also close #37 as being the result of a bug from another module. The ultimate cause is actor.overrides being unavailable. If you want to simulate the bug to see for yourself, something like this should do it:

libWrapper.register(
  "wire",
  "Actor.prototype.applyActiveEffects",
  (fn, ...args) => {
    fn(...args)
    const [actor] = args
    delete actor.overrides
  },
  "WRAPPER"
)
teroparvinen commented 1 year ago

Is the module a publicly available one? Would be good to know in case someone else runs into this

TheGiddyLimit commented 1 year ago

Is the module a publicly available one? Would be good to know in case someone else runs into this

After a fashion: https://raw.githubusercontent.com/TheGiddyLimit/plutonium-next/master/module-foundry10.json

teroparvinen commented 1 year ago

Understood. Thanks for the notice.