Recommended way for shutting down Simulator gracefully?

,

Is there a recommended way of shutting down a Simulator gracefully? Right now, I call Application.Quit(), but wondering if there is a “cleaner” way of doing this that works well with the SDK/engine?

I ask because there is a good amount of output from calling Application.Quit(), which I’m not sure is expected or not.

Example of what I do now:

IEnumerator CloseAfter(int i)
{
    this.LogWarn($"Closing after {i} seconds...");
    yield return new WaitForSeconds(i);
    this.LogWarn($"Closing...");
    Application.Quit();
}

Example output that is logged:

(Filename: ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Log/Logger.cs Line: 130)

15:33:28.715 (coherence) AutoSimulatorConnection: Disconnected. GracefulClose
UnityEngine.StackTraceUtility:ExtractStackTrace () (at C:/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:37)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:LogError (object)
Coherence.Log.UnityLogger:BuildAndPrintLog (Coherence.Log.LogLevel,string,System.Text.StringBuilder,System.ValueTuple`2<string, object>[]) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Log/UnityLogger.cs:220)
Coherence.Log.Logger:LogImpl (Coherence.Log.LogLevel,string,System.ValueTuple`2<string, object>[]) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Log/Logger.cs:195)
Coherence.Log.Logger:Error (string,System.ValueTuple`2<string, object>[]) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Log/Logger.cs:130)
Coherence.Log.UnityLogger:Error (string,System.ValueTuple`2<string, object>[]) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Log/UnityLogger.cs:142)
Coherence.Simulator.AutoSimulatorConnection:NetworkOnDisconnected (Coherence.Connection.ConnectionCloseReason) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.UI/AutoSimulatorConnection.cs:117)
Coherence.Core.ClientCore:OnDisconnect (Coherence.Connection.ConnectionCloseReason) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Core/ClientCore.cs:255)
Coherence.Brisk.Brisk:Disconnect (Coherence.Connection.ConnectionCloseReason,bool) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Brisk/Brisk.cs:144)
Coherence.Core.ClientCore:Disconnect (Coherence.Connection.ConnectionCloseReason,bool) (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Core/ClientCore.cs:313)
Coherence.Core.ClientCore:Dispose () (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Core/ClientCore.cs:774)
Coherence.Toolkit.CoherenceBridge:Dispose () (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Toolkit/CoherenceBridge.cs:614)
Coherence.Toolkit.CoherenceBridge:OnApplicationQuit () (at ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Toolkit/CoherenceBridge.cs:763)

(Filename: ./Library/PackageCache/io.coherence.sdk@1.0.0/Coherence.Log/Logger.cs Line: 130)

Setting up 12 worker threads for Enlighten.
debugger-agent: Unable to listen on 1516
PlayerConnection::CleanupMemory Statistics:
[ALLOC_TEMP_TLS] TLS Allocator
  StackAllocators :
    [ALLOC_TEMP_MAIN]
      Peak usage frame count: [4.0 KB-8.0 KB]: 314 frames, [8.0 KB-16.0 KB]: 3 frames, [16.0 KB-32.0 KB]: 1 frames, [0.5 MB-1.0 MB]: 1 frames, [2.0 MB-4.0 MB]: 1 frames
      Initial Block Size 4.0 MB
      Current Block Size 4.0 MB
      Peak Allocated Bytes 2.8 MB
      Overflow Count 0
    [ALLOC_TEMP_Background Job.worker 6]
      Initial Block Size 32.0 KB
      Current Block Size 32.0 KB
      Peak Allocated Bytes 54 B
      Overflow Count 0
...
1 Like

Looks good to me? You have one line of debug from coherence, which mentions “GracefulClose”, so it seems in order :slight_smile:
The rest is call stack, and some other Unity stuff (Enlighten? Then some Job System allocators?)

If anything, you could call Disconnect on the CoherenceBridge, but I think it’s being called automatically in its OnDisable/OnDestroy here, so I think it would give you the same log in the end.

1 Like

OK to mark Ciro’s answer as the solution?

This is now an FAQ.