searica / TerrainTools

GNU General Public License v3.0
0 stars 0 forks source link

`ArgumentOutOfRangeException` when reloading config #4

Closed nbusseneau closed 3 months ago

nbusseneau commented 3 months ago

Hey, thanks for your mods :)

Noticed an issue with config reload.

Minimal reproduction setup with clean r2modman profile

Reproduction steps

Expected

Observed

[Warning:AdvancedTerrainModifiers] Exception thrown at event InvokeOnConfigFileReloaded in <>c.<Awake>b__41_0:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <17d9ce77f27a4bd2afb5ba32c9bea976>:0
  at TerrainTools.Helpers.InitManager.RemovePieceInPieceTable (TerrainTools.Configs.ToolDB toolDB) [0x0009b] in <00cb98da6cf048a9b4b59112510b2092>:0
  at TerrainTools.Helpers.InitManager.UpdateTools () [0x00026] in <00cb98da6cf048a9b4b59112510b2092>:0
  at TerrainTools.Helpers.InitManager.UpdatePlugin () [0x00000] in <00cb98da6cf048a9b4b59112510b2092>:0
  at TerrainTools.TerrainTools+<>c.<Awake>b__41_0 () [0x00007] in <00cb98da6cf048a9b4b59112510b2092>:0
  at TerrainTools.Extensions.EventExtensions.SafeInvoke (System.Action events) [0x00018] in <00cb98da6cf048a9b4b59112510b2092>:0

Additional information

I noticed this because the same codepath is called and throws the same exception when config is reloaded as part of a client connecting to a server, just on a different event:

[Warning:Jotunn.EventExtensions] Exception thrown at event InvokeOnConfigurationSynchronized in <>c.<Awake>b__41_2:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <17d9ce77f27a4bd2afb5ba32c9bea976>:0
  at TerrainTools.Helpers.InitManager.RemovePieceInPieceTable (TerrainTools.Configs.ToolDB toolDB) [0x0009b] in <00cb98da6cf048a9b4b59112510b2092>:0
  at TerrainTools.Helpers.InitManager.UpdateTools () [0x00026] in <00cb98da6cf048a9b4b59112510b2092>:0
  at TerrainTools.Helpers.InitManager.UpdatePlugin () [0x00000] in <00cb98da6cf048a9b4b59112510b2092>:0
  at TerrainTools.TerrainTools+<>c.<Awake>b__41_2 (System.Object obj, Jotunn.Utils.ConfigurationSynchronizationEventArgs args) [0x00007] in <00cb98da6cf048a9b4b59112510b2092>:0
  at Jotunn.EventExtensions.SafeInvoke[TEventArg] (System.EventHandler`1[TEventArgs] events, System.Object sender, TEventArg arg1) [0x00018] in D:\Projects\Jotunn\JotunnLib\Extensions\EventExtensions.cs:107
searica commented 3 months ago

Thanks for letting me know. Based on my testing this update should resolve the issue. Please try using the dll or zip (import as local mod in r2modman) from here https://github.com/searica/TerrainTools/tree/dev/Publish/ThunderStore but make sure to also update Jotunn to 2.20.1

Then please let me know if the issue is resolved for you. If I don't hear anything then in a few days I will go ahead with updating the mod on Thunderstore.

nbusseneau commented 3 months ago

Confirm I can't reproduce the issue with the new version, both when reloading config regularly or via server > client synchronization. Thanks!

searica commented 3 months ago

Perfect, I have now updated the mod on Thunderstore. Thanks for confirming the fixes worked as intended!