Skip to content

Commit dbea9d8

Browse files
committed
Fix crash on exit
1 parent 8989ae9 commit dbea9d8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎Torch.Mod/ModCommunication.cs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public static void Register()
4242
public static void Unregister()
4343
{
4444
MyLog.Default.WriteLineAndConsole("TORCH MOD: Unregistering mod communication.");
45-
MyAPIGateway.Multiplayer.UnregisterMessageHandler(NET_ID, MessageHandler);
46-
_closing = true;
45+
MyAPIGateway.Multiplayer?.UnregisterMessageHandler(NET_ID, MessageHandler);
4746
ReleaseLock();
48-
_task.Wait();
47+
_closing = true;
48+
//_task.Wait();
4949
}
5050

5151
private static void MessageHandler(byte[] bytes)
@@ -183,13 +183,17 @@ public static void SendMessageToServer(MessageBase message)
183183

184184
private static void ReleaseLock()
185185
{
186+
if(_lock==null)
187+
return;
186188
while(!_lock.TryAcquireExclusive())
187189
_lock.ReleaseExclusive();
188190
_lock.ReleaseExclusive();
189191
}
190192

191193
private static void AcquireLock()
192194
{
195+
if (_lock == null)
196+
return;
193197
ReleaseLock();
194198
_lock.AcquireExclusive();
195199
_lock.AcquireExclusive();

0 commit comments

Comments
 (0)