CounterStrikeSharp
CounterStrikeSharp copied to clipboard
Help me
[17:59:41.605] CSSharp: Native ab9aa921 was invoked on a non-main thread Error inserting new player: Invoked on a non-main thread
You are trying to call a native game function from a thread that is not the main thread. Most likely you are trying to work with CCSPlayerController (as an example) in a Task function. You can try using Server.NextFrame to work with CCSPlayerController (for example) to return to the main thread, or cache the data before it gets into the Task function. I hope you understood what I meant. Or better, share the code snippet where this problem occurs.
for example
private HookResult OnEventPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
{
if (@event.Userid == null) return HookResult.Continue;
CCSPlayerController pl = new(@event.Userid.Handle);
...
Server.NextFrame(() =>
{
...
pl.PrintToChat($"Message"));
});
}
if you call @event.Userid.PrintToChat in Server.NextFrame, it will be your mistake sometimes this happens when using a Task and not a Server.NextFrame
not sure if the issue has been resolved or not, but that native is SetSchemaValueByName.
@KillStr3aK an error occurs in this plugin, can you fix it for me?
https://github.com/schwarper/cs2-tags
@KillStr3aK an error occurs in this plugin, can you fix it for me?
https://github.com/schwarper/cs2-tags
I believe the issue is happening here and it could be fixed with the method mentioned above (the same semantic issue occurs in multiple places)