nwn-dotnet / Anvil

A Neverwinter Nights Server API
https://nwn-dotnet.github.io/Anvil
MIT License
24 stars 9 forks source link

VirtualMachine throws IndexOutOfRangeException after reloading plugin #764

Open jakkn opened 7 months ago

jakkn commented 7 months ago

This happens after reloading a service that subscribes to an event that is also subscribed to in nss. When the event fires after the reload, the process crashes.

The exception is thrown from https://github.com/nwn-dotnet/Anvil/blob/ca84ad28e2bfadaf1c06fc58a82cfbeb776dc58d/NWN.Anvil/src/main/API/Utils/VirtualMachine.cs#L105

For detailed repro steps and code, see https://github.com/jakkn/NWN.ProcessEventInfiniteLoopRepro

nwserver-1  | F [2024/05/01 19:04:48.676] [Anvil.Services.UnhandledExceptionLogger] Unhandled Exception.
nwserver-1  | System.IndexOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the array.
nwserver-1  |    at NWN.Native.API.NativeArray`1.set_Item(Int32 index, T value)
nwserver-1  |    at Anvil.API.VirtualMachine.PushScriptContext(UInt32 oid, Int32 scriptEventId) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Utils/VirtualMachine.cs:line 208
nwserver-1  |    at Anvil.API.VirtualMachine.ExecuteInScriptContext(Action action, UInt32 objectId, Int32 scriptEventId) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Utils/VirtualMachine.cs:line 105
nwserver-1  |    at Anvil.API.Events.HookEventFactory.ProcessEvent[TEvent](EventCallbackType eventType, TEvent eventData, Boolean executeInScriptContext) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Events/Native/HookEventFactory.cs:line 54
nwserver-1  |    at Anvil.API.Events.OnStoreRequestSell.Factory.OnRequestSell(Void* pCreature, UInt32 oidItemToSell, UInt32 oidStore) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Events/Native/StoreEvents/OnStoreRequestSell.cs:line 59
nwserver-1  | Unhandled exception. System.IndexOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the array.
nwserver-1  |    at NWN.Native.API.NativeArray`1.set_Item(Int32 index, T value)
nwserver-1  |    at Anvil.API.VirtualMachine.PushScriptContext(UInt32 oid, Int32 scriptEventId) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Utils/VirtualMachine.cs:line 208
nwserver-1  |    at Anvil.API.VirtualMachine.ExecuteInScriptContext(Action action, UInt32 objectId, Int32 scriptEventId) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Utils/VirtualMachine.cs:line 105
nwserver-1  |    at Anvil.API.Events.HookEventFactory.ProcessEvent[TEvent](EventCallbackType eventType, TEvent eventData, Boolean executeInScriptContext) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Events/Native/HookEventFactory.cs:line 54
nwserver-1  |    at Anvil.API.Events.OnStoreRequestSell.Factory.OnRequestSell(Void* pCreature, UInt32 oidItemToSell, UInt32 oidStore) in /home/runner/work/Anvil/Anvil/NWN.Anvil/src/main/API/Events/Native/StoreEvents/OnStoreRequestSell.cs:line 59
nwserver-1  |  NWNX Signal Handler:
nwserver-1  | ==============================================================
nwserver-1  |  NWNX 8193.36-12 (41dd0c2) has crashed. Fatal error: Program aborted (6).
nwserver-1  |  Please file a bug at https://github.com/nwnxee/unified/issues
nwserver-1  | ==============================================================
nwserver-1  |
nwserver-1  |   Backtrace:
nwserver-1  |     /nwn/nwnx/NWNX_Core.so(_ZN7NWNXLib8Platform13GetStackTraceB5cxx11Eh+0x3b) [0x7fae1a7574fb]
nwserver-1  |     /nwn/nwnx/NWNX_Core.so(nwnx_signal_handler+0xac) [0x7fae1a704abc]
nwserver-1  |     /lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7fae1a6b7420]
nwserver-1  |     /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcb) [0x7fae1a1a000b]
nwserver-1  |     /lib/x86_64-linux-gnu/libc.so.6(abort+0x12b) [0x7fae1a17f859]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x64d3c2) [0x7fae1164d3c2]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x64d2e2) [0x7fae1164d2e2]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x40f735) [0x7fae1140f735]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x40f816) [0x7fae1140f816]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x360f69) [0x7fae11360f69]
nwserver-1  |     [0x7fad970b2525]
nwserver-1  |  NWNX Signal Handler:
nwserver-1  | ==============================================================
nwserver-1  |  NWNX 8193.36-12 (41dd0c2) has crashed. Fatal error: Segmentation fault (11).
nwserver-1  |  Please file a bug at https://github.com/nwnxee/unified/issues
nwserver-1  | ==============================================================
nwserver-1  |
nwserver-1  |   Backtrace:
nwserver-1  |     /nwn/nwnx/NWNX_Core.so(_ZN7NWNXLib8Platform13GetStackTraceB5cxx11Eh+0x3b) [0x7fae1a7574fb]
nwserver-1  |     /nwn/nwnx/NWNX_Core.so(nwnx_signal_handler+0xac) [0x7fae1a704abc]
nwserver-1  |     /lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7fae1a6b7420]
nwserver-1  |     /lib/x86_64-linux-gnu/libc.so.6(abort+0x213) [0x7fae1a17f941]
nwserver-1  |     /nwn/nwnx/NWNX_Core.so(nwnx_signal_handler+0x185) [0x7fae1a704b95]
nwserver-1  |     /lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7fae1a6b7420]
nwserver-1  |     /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcb) [0x7fae1a1a000b]
nwserver-1  |     /lib/x86_64-linux-gnu/libc.so.6(abort+0x12b) [0x7fae1a17f859]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x64d3c2) [0x7fae1164d3c2]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x64d2e2) [0x7fae1164d2e2]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x40f735) [0x7fae1140f735]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x40f816) [0x7fae1140f816]
nwserver-1  |     /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.18/libcoreclr.so(+0x360f69) [0x7fae11360f69]
nwserver-1  |     [0x7fad970b2525]
nwserver-1 exited with code 127