Repository navigation
Open
Description
Calling IServerService.SendRconCommand("loadfs ...") from OnGameModeInit intermittently crashes the server with an Access Violation (0xC0000005).
Minimal reproduction:
[Event]
public void OnGameModeInit()
{
Console.WriteLine("BEFORE");
serverService.SendRconCommand("loadfs EntryMap");
Console.WriteLine("AFTER");
}The crash occurs before "AFTER" is printed.
Stack trace:
Fatal error.
0xC0000005
at SampSharp.OpenMp.Core.Api.IConsoleComponent.<Send>g____PInvoke|3_0(IntPtr, SampSharp.OpenMp.Core.Std.StringView, SampSharp.OpenMp.Core.Api.ConsoleCommandSenderData ByRef)
at SampSharp.OpenMp.Core.Api.IConsoleComponent.Send(System.String, SampSharp.OpenMp.Core.Api.ConsoleCommandSenderData ByRef)
at SampSharp.Entities.SAMP.ServerService.SendRconCommand(System.String)
at CTF.Host.GameModeInit.OnGameModeInit()
at DynamicClass.lambda_method194(System.Runtime.CompilerServices.Closure, System.Object, System.Object[], System.IServiceProvider, SampSharp.Entities.IEntityManager)
at SampSharp.Entities.EventDispatcher+<>c__DisplayClass16_0.<CreateTargetSite>b__0(System.Object, SampSharp.Entities.EventContext)
at SampSharp.Entities.EventDispatcher.InnerInvoke(SampSharp.Entities.EventContext, Event, System.Object)
at SampSharp.Entities.EventDispatcher+<>c__DisplayClass17_0.<CreateEventInvoke>b__0(SampSharp.Entities.EventContext)
at CTF.Host.Middlewares.GlobalExceptionHandler.Invoke(SampSharp.Entities.EventContext)
at SampSharp.Entities.EventDispatcher+<>c__DisplayClass17_0.<CreateEventInvoke>b__1(System.ReadOnlySpan`1<System.Object>)
at SampSharp.Entities.EventDispatcher.Invoke(System.String, System.ReadOnlySpan`1<System.Object>)
at SampSharp.Entities.EcsHost.OnGameModeInit()
at SampSharp.Entities.EcsHost.Start(SampSharp.OpenMp.Core.IStartupContext)
at SampSharp.Entities.HostContextBinder.OnContextInitialized(System.Object, System.EventArgs)
at SampSharp.OpenMp.Core.StartupContext.InitializeUsing(SampSharp.OpenMp.Core.IStartup)
at SampSharp.Entrypoint.Initialize(SampSharp.OpenMp.Core.SampSharpInitParams)
Notes:
- The issue is intermittent.
- Sometimes the command succeeds, sometimes it crashes.
- The filterscript being loaded does not appear to matter.
- Delaying the call (e.g.
await Task.Delay(5000)) prevents the crash.
Activity
DevD4v3 commentedon Jun 8, 2026
While debugging, I observed that
IConsoleComponent.Send()is invoked with_handle == 0x0000000000000000.The generated wrapper exposes
HasValue => _handle != default, butSend()does not validate the handle before invoking the native P/Invoke call.ikkentim commentedon Jun 8, 2026
Interesting, I may need to look into a later moment for triggering OnGameModeInit instead on component initialization.
ikkentim commentedon Jun 8, 2026
Based on the open.mp code, we should use
Component.onReadyforOnGameModeInitto match the pawn behavior. This requires asetOnReadyhandler + implementation to be added tosampsharp-api->SampSharpInitParamsand.Coreto wire it up correctly.DevD4v3 commentedon Jun 14, 2026
@ikkentim The crash is still occurring, but now the stack trace has changed:
DevD4v3 commentedon Jun 14, 2026
I just noticed that the same crash occurs in a timer.