altv-issues icon indicating copy to clipboard operation
altv-issues copied to clipboard

C# Server Side Crashing Alt.OnClient and Alt.OffClient

Open MosIbOad opened this issue 1 year ago • 0 comments

Description of the problem

I think Alt.OffClient is crashing the server

Reproduction steps

Server Side Code (C#):

// server crashing
[Command("test")]
public static void testcmd(PlayerHandle player)
{
    player.Emit("triggerTestEvent", "testOnClientEvent", "myData");
    Function? func = null;
    func = Alt.OnClient("testOnClientEvent", (PlayerHandle _player, string value) =>
    {
        Alt.OffClient("testOnClientEvent", func); // server crashed
        player.SendChatMessage("triggered value: " + value); // triggered value: myData
    });
}

Client Side Code (JS):

alt.onServer('triggerTestEvent', (triggerName, Data) => {
    alt.emitServer(triggerName, Data);
});

Server Console:

< ==== UNHANDLED EXCEPTION ==== >
 Received an unhandled exception from : System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at AltV.Net.Core.OnClientEvent(IntPtr playerPointer, String name, IntPtr[] args)
Unhandled exception. System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at AltV.Net.Core.OnClientEvent(IntPtr playerPointer, String name, IntPtr[] args)

Expected behaviour

If you try this code you may see that the server crashes.

Additional context

No response

Operating system

Windows 11

Version

16.2.8 (release)

Crashdump ID

No response

Confirmation of issue's presence

  • [X] By submitting this ticket, I affirm that I have verified the presence of this issue on the latest RC (Release Candidate) version available at the time of writing this ticket.

MosIbOad avatar Sep 18 '24 17:09 MosIbOad