mclemente / fvtt-condition-lab-triggler

Condition Lab & Triggler module for Foundry Virtual Tabletop
GNU General Public License v3.0
6 stars 4 forks source link

Incompatibility with Year Zero Engine: Combat module #57

Closed DC23 closed 1 week ago

DC23 commented 2 weeks ago

Describe the bug Reporting this here since I believe the issue is caused by this module. The YZE: Combat module implements functionality by adding two custom status effects to the Foundry array. It does this through the functions in slow-and-fast-actions.js, calling push to add the new status objects. This works when Condition Lab is not installed but raises the exception "Uncaught (in promise) TypeError: Cannot add property 34, object is not extensible" when the Condition Lab module is installed.

To Reproduce Steps to reproduce the behavior:

  1. Create a new world with the Dragonbane game system.
  2. Activate the CLT and YZE: Combat Modules.
  3. Open the browser console.
  4. In the YZE: Combat module settings, check the "Enable Single Action" box.
  5. Save the module settings.
  6. Reload the application.
  7. The "object is not extensible" exception will be seen in the console and from this point on, the YZE: Combat module will not work correctly.

I have alternate steps to reproduce that don't require the YZE: Combat module at all. With only the CLT module active and nothing else, then going into either the console or a script macro and reproducing the same method that the YZE: Combat module is using to add its custom status effects I can reproduce the issue.

Expected behavior Since the YZE: Combat module works correctly when active by itself, I expect it to continue to work correctly when the CLT module is active as well. CLT shouldn't be modifying Foundry data structures in such a way that they no longer function when accessed by other modules. Note that I am not a maintainer or developer on YZE: Combat, and while the repro steps make this issue look on the surface like a problem with that module, I believe the issue is caused by a change that CLT appears to be making to the data structure containing the status effect objects, such that it can no longer be modified by other modules.

Environment Info (please complete the following information):

Additional context Add any other context about the problem here.

DC23 commented 1 week ago

I've looked into this further. It's almost certainly due to the Object.freeze(CONFIG.statusEffects) line in the ready hook for this module. The YZE:C module pushes its custom status effects during the ready hook as well, meaning it's a race condition between the modules to modify the CONFIG.statusEffects array.

This behaviour means that CLT will be incompatible with any other modules that also attempt to modify the status effects array during the ready hook stage of Foundry initialisation.

I've been able to isolate the code from YZE:C to a script macro. Running it manually in Foundry I can get YZE:C working again, which just tells me that at some point later on, CLT changes the status effects array back to a mutable object, though I don't know the code well enough to say where exactly this happens. It does suggest a compatibility workaround on the YZE:C side that I'm looking at, though that doesn't change this bug report. It is still the case that CLT behaviour - locking of CONFIG.statusEffects during the ready hook - is directly causing the YZE:C module to break.