CounterStrikeSharp icon indicating copy to clipboard operation
CounterStrikeSharp copied to clipboard

Help me

Open jxn78 opened this issue 7 months ago • 5 comments

[17:59:41.605] CSSharp: Native ab9aa921 was invoked on a non-main thread Error inserting new player: Invoked on a non-main thread

jxn78 avatar Apr 18 '25 16:04 jxn78

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.

xMaZax avatar Apr 19 '25 08:04 xMaZax

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

darkerz7 avatar Apr 20 '25 10:04 darkerz7

not sure if the issue has been resolved or not, but that native is SetSchemaValueByName.

KillStr3aK avatar May 10 '25 09:05 KillStr3aK

@KillStr3aK an error occurs in this plugin, can you fix it for me?

https://github.com/schwarper/cs2-tags

jxn78 avatar May 11 '25 08:05 jxn78

@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)

KillStr3aK avatar May 12 '25 04:05 KillStr3aK