Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit bbf8015

Browse files
more thread safety
1 parent ea40a34 commit bbf8015

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

Scripts/Netcode/Client/ENetClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ public async void Start(string ip, ushort port)
7373
/// </summary>
7474
public void Stop() => ENetCmds.Enqueue(new ENetCmd(ENetOpcode.ClientWantsToDisconnect));
7575

76-
public void CancelTask()
77-
{
78-
CancelTokenSource.Cancel();
79-
}
76+
public void CancelTask() => ENetCmds.Enqueue(new ENetCmd(ENetOpcode.CancelTask));
8077

8178
public void Log(object obj) => Logger.Log($"[Client]: {obj}", ConsoleColor.Yellow);
8279

@@ -138,6 +135,9 @@ private async Task ENetThreadWorker(string ip, ushort port)
138135
case ENetOpcode.ClientWantsToDisconnect:
139136
peer.Disconnect(0);
140137
break;
138+
case ENetOpcode.CancelTask:
139+
CancelTokenSource.Cancel();
140+
break;
141141
}
142142
}
143143

Scripts/Netcode/Common/_Opcodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public enum ENetOpcode
115115
RestartServer,
116116
ClientWantsToExitApp,
117117
ClientWantsToDisconnect,
118+
CancelTask,
118119
Dispose
119120
}
120121
}

Scripts/Scenes/Main/NetworkManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static void CancelClientConnectingTokenSource()
203203
return;
204204

205205
ClientConnectingTokenSource.Cancel();
206-
GameClient.CancelTask(); // THREAD SAFETY VIOLATION
206+
GameClient.CancelTask();
207207
}
208208
}
209209

0 commit comments

Comments
 (0)