Skip to content

Commit

Permalink
Delay dispose of CancellationTokenSource when quitting
Browse files Browse the repository at this point in the history
Quitting in Unity fires a number of events and callbacks. 

`MonoBehaviour.OnApplicationQuit` is called before `Application.wantsToQuit`
which leads to undesired behaviour. `Application.wantsToQuit` can be used to interrupt a quit process, so you can shut down gracefully. If this is utilized, the AgonesSDK has already dispose the cancellation token and future calls will fail. 

Reference: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Application-wantsToQuit.html

Same solution as in UniRX: neuecc/UniRx#463
  • Loading branch information
kaboing authored Dec 27, 2024
1 parent 8166704 commit 9d92406
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sdks/unity/AgonesSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private void Awake()
{
String port = Environment.GetEnvironmentVariable("AGONES_SDK_HTTP_PORT");
sidecarAddress = "http://localhost:" + (port ?? "9358");
Application.quitting += OnApplicationQuitting;
}

private void Start()
Expand All @@ -79,10 +80,15 @@ private void Start()
HealthCheckAsync();
}

private void OnApplicationQuit()
private void OnApplicationQuitting()
{
cancellationTokenSource.Dispose();
}

private void OnDestroy()
{
Application.quitting -= OnApplicationQuitting;
}
#endregion

#region AgonesRestClient Public Methods
Expand Down

0 comments on commit 9d92406

Please sign in to comment.