@@ -18,7 +18,7 @@ namespace Torch.Mod
1818 public static class ModCommunication
1919 {
2020 public const ushort NET_ID = 4352 ;
21- private static bool _closing ;
21+ private static bool _closing = false ;
2222 private static BlockingCollection < MessageBase > _processing ;
2323 private static MyConcurrentPool < IncomingMessage > _messagePool ;
2424 private static List < IMyPlayer > _playerCache ;
@@ -32,6 +32,7 @@ public static void Register()
3232
3333 MyAPIGateway . Multiplayer . RegisterMessageHandler ( NET_ID , MessageHandler ) ;
3434 //background thread to handle de/compression and processing
35+ _closing = false ;
3536 MyAPIGateway . Parallel . StartBackground ( DoProcessing ) ;
3637 MyLog . Default . WriteLineAndConsole ( "TORCH MOD: Mod communication registered successfully." ) ;
3738 }
@@ -40,7 +41,7 @@ public static void Unregister()
4041 {
4142 MyLog . Default . WriteLineAndConsole ( "TORCH MOD: Unregistering mod communication." ) ;
4243 MyAPIGateway . Multiplayer ? . UnregisterMessageHandler ( NET_ID , MessageHandler ) ;
43- _processing . CompleteAdding ( ) ;
44+ _processing ? . CompleteAdding ( ) ;
4445 _closing = true ;
4546 //_task.Wait();
4647 }
@@ -59,6 +60,8 @@ public static void DoProcessing()
5960 try
6061 {
6162 var m = _processing . Take ( ) ;
63+ MyLog . Default . WriteLineAndConsole ( $ "Processing message: { m . GetType ( ) . Name } ") ;
64+
6265 if ( m is IncomingMessage )
6366 {
6467 MessageBase i ;
@@ -129,9 +132,9 @@ public static void DoProcessing()
129132
130133 MyLog . Default . WriteLineAndConsole ( "TORCH MOD: COMMUNICATION THREAD: EXIT SIGNAL RECEIVED!" ) ;
131134 //exit signal received. Clean everything and GTFO
132- _processing . Dispose ( ) ;
135+ _processing ? . Dispose ( ) ;
133136 _processing = null ;
134- _messagePool . Clean ( ) ;
137+ _messagePool ? . Clean ( ) ;
135138 _messagePool = null ;
136139 _playerCache = null ;
137140 }
@@ -146,7 +149,6 @@ public static void SendMessageTo(MessageBase message, ulong target)
146149
147150 message . Target = target ;
148151 message . TargetType = MessageTarget . Single ;
149- MyLog . Default . WriteLineAndConsole ( $ "Sending message of type { message . GetType ( ) . FullName } ") ;
150152 _processing . Add ( message ) ;
151153 }
152154
0 commit comments