Closed aldocd4 closed 1 year ago
Important note: the timer used here is the C# timer (System.Timers) and not the godot timer node.
I believe this bug occurs because the native C# timer is not single-threaded. It worked on latest v4.0 stable version and the 2 dev snapshots of 4.1.
Maybe this change is intended and is not a bug.
You need to use other methods as you are not allowed to manipulate it from the main thread, use something like deferred calls, this is because processing got reworked on 4.1.dev I believe
Don't think this is a bug
Edit: My bad, didn't realize this was get_multiplayer
, I'm unsure why it has a thread check like that, that might be a bug yes
The get_multiplayer
method checks if we are in the main thread:
This seems intentional, the PR says:
Multiplayer API is not thread safe.
The multiplayer code (rpc as example) is not thread safe, the Node API does not care about this, so we need to discuss if we want to implement safety at Node level or Multiplayer level.
Using a Godot timer should avoid the issue since it will tick in the main thread. But if you want to keep using C# timers, you should be able to use CallDeferred
. You can use GodotObject.CallDeferred
or a Callable
, here's an example using a Callable
:
var timer = new Timer(14000);
timer.Elapsed += (object sender, ElapsedEventArgs e) =>
{
Callable.From(() => RpcId(peerId, "UpdateFightStep", 1)).CallDeferred();
};
timer.AutoReset = true;
timer.Start();
Closing per comment above (and OP's acknowledgement of it).
Godot version
v4.1.dev3.mono.official [a67d37f7c]
System information
Windows 11 - v4.1.dev3 - Vulkan
Issue description
Hello,
I'm playing with the latest 4.1 dev snapshot (3) and C#, and it seems that my multiplayer game crashes with the following stacktrace:
It's working correctly on 4.1 dev 1 and 4.1 dev 2 snapshots.
Steps to reproduce
A timer that trigger a simple function making an rpc call:
Minimal reproduction project
I will try to reproduce it in a small project.