Introducing the Loom class, that is able to call unsafe methods from sub threads, on the main thread.
This update should clear out most of the dangerous crash messages, mostly caused by Player.Disconnect()
Testing with a C# timer, the log comes up with:
Code:
[5/13/2016 1:32:57 PM] [Error] Same? 6 - 1
[5/13/2016 1:32:57 PM] [Error] Nope, invoking
[5/13/2016 1:32:57 PM] [Error] Same? 1 - 1
The log shows that after detecting that the call is being made from a different thread, It starts doing It from the main one.
Testing with new Thread() at Connection event:
Code:
[5/13/2016 1:39:43 PM] [Error] Same? 6 - 1
[5/13/2016 1:39:43 PM] [Error] Nope, invoking
[5/13/2016 1:39:43 PM] [Error] Same? 1 - 1
Same results.
Code that was used to test this:
C#:
public void Disconnect()
{
if (this.IsOnline)
{
Logger.LogError("Same? " + Thread.CurrentThread.ManagedThreadId + " - " + Bootstrap.CurrentThread.ManagedThreadId);
if (Thread.CurrentThread.ManagedThreadId != Bootstrap.CurrentThread.ManagedThreadId)
{
Logger.LogError("Nope, invoking");
Loom.QueueOnMainThread(() => {
Disconnect();
});
return;
}
Server.GetServer().RemovePlayer(uid);
this.ourPlayer.netUser.Kick(NetError.Facepunch_Kick_RCON, false);
}
}
I added support for the Interpreters to use the Loom class, but I can't come up with an example for them yet...
Any other stuff that can cause the server to crash popup by using UnityEngine.Object.FindobjectsOfType... method should be calling the Loom class to avoid them.
I made some other changes that you can check out here:
https://github.com/Notulp/Fougerite/commit/45615eefd9d49033ff725d225c324e749c4911bd#diff-0f20521893282f654a5ce046948d2842L436
The loom class:
https://github.com/Notulp/Fougerite/blob/master/Fougerite/Fougerite/Loom.cs
When calling loom class, there is like a 0,1 second delay before performing the method, but It doesn't cause lagg.
Some thread API for the "Script" plugins:
https://github.com/Notulp/Fougerite/blob/master/Fougerite/Fougerite/Util.cs#L711