tposney / midi-qol

Other
5 stars 0 forks source link

[v 10.0.21] args[0].workflow overflowing macro.execute(args[0]) when executing on a different client #1071

Open tposney opened 2 years ago

tposney commented 2 years ago

In GitLab by @gantonaci on Nov 11, 2022, 07:18

I have a macro that stopped working after upgrading to v10. After some digging I could reproduce the error with a simple macro.

I have two script macros, macroPlayer and macroGM.

macroPlayer is called by Midi-QoL in a spell (OnUse, After Active Efects)

macroGM flagged to "Execute Macro As GM"

MacroPlayer is:

let macro = game.macros.find(i => i.name === "MacroGM");
macro.execute(args[0]);

MacroGM is:

console.log(args);

If I, as the GM, roll the spell, the macro executes flawless and args is outputted to the GM console. If my player roll the spell nothing is outputted to the GM console. The player console gets an error:

Advanced Macros | RangeError: Maximum call stack size exceeded
    at gt (is-binary.js:24:17)
    at gt (is-binary.js:45:63)
    at gt (is-binary.js:45:63)
    ... repeats dozens of times
    at gt (is-binary.js:45:63)
    at t.value (index.js:40:17)
    at s.value (manager.js:247:45)
    at i.value (socket.js:173:17)
    at i.value (socket.js:132:18)
    at executeResponse (Macros.js:271:16)
    at new Promise (<anonymous>)
    at FurnaceMacros.executeMacroAsGM (Macros.js:268:33)
    at async Macro.executeMacro (Macros.js:239:12)

The following is a workaroud for macroPlayer:

let macro = game.macros.find(i => i.name === "MacroGM");
delete args[0].workflow;
macro.execute(args[0]);

Versions and modules: FoundryVTT 10, build 288

DnD5e 2.0.3

Advanced Macro 1.17.3

DAE 10.013

Find the CUlprit 1.4.6

liwrapper 1.12.10.0

Midi QoL 10.0.21

Socketlib 1.012

Times Up 10.0.2

tposney commented 2 years ago

You're right that's a problem. In v10 I discontinued using advanced macros internally which allows me to pass self referential objects (like workflow and actor - if the actor is an unlinked actor) as arguments to the macro, which is convenient most of the time.

This does mean args[0] is no longer safe to pass to a macro.execute when advanced macros is active.

I can't think of an easy way for midi to know if you are going to call an execute as GM macro inside your macro.

For the moment, deleting args[0].workflow and args[0].actor is the best workaround.