Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
80e9801
native stopwatch on exit
NickKhalow May 28, 2026
c4ac040
native implementaiton
NickKhalow May 28, 2026
40dc008
move to hide the native
NickKhalow May 28, 2026
19f92e4
fix compilation
NickKhalow May 28, 2026
fae0ce7
add missing import
NickKhalow May 28, 2026
d305e00
subscribe to exit from entry point
NickKhalow May 29, 2026
d2da965
no-livekit-mode flag
NickKhalow Jun 3, 2026
20b118a
remove unused import
NickKhalow Jun 3, 2026
4527665
Merge branch 'main' into chore/delay-on-exit-fix
NickKhalow Jun 3, 2026
41eded1
manually destroy all OnDestroy callbacks
NickKhalow Jun 3, 2026
c0218fe
add editor guard becaue method uses dangerous API for Editor mode
NickKhalow Jun 3, 2026
14da527
gracefull cleanup for crashdetector and prefs
NickKhalow Jun 4, 2026
cd0d857
soft-shutdown flag
NickKhalow Jun 4, 2026
106edf4
terminate process after graceful shutdown
NickKhalow Jun 4, 2026
100706e
sentry graceful flush
NickKhalow Jun 4, 2026
93894b0
native shutdown stopwatch via flags
NickKhalow Jun 4, 2026
89d5fc0
Merge branch 'dev' into chore/delay-on-exit-fix
NickKhalow Jun 4, 2026
4941684
Update Explorer/Assets/DCL/Infrastructure/Utility/ExitUtils.cs
NickKhalow Jun 4, 2026
9a28f16
Revert "Update Explorer/Assets/DCL/Infrastructure/Utility/ExitUtils.cs"
NickKhalow Jun 4, 2026
cd25a0c
shutdown stopwatch
NickKhalow Jun 4, 2026
df6989b
remove complete wait
NickKhalow Jun 4, 2026
f66a2aa
drop dispose on about to exit
NickKhalow Jun 4, 2026
01f3907
restore Complete call
NickKhalow Jun 4, 2026
a9a6360
disable IsAboutToExit in editor
NickKhalow Jun 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using DCL.AvatarRendering.AvatarShape.ComputeShader;
using DCL.AvatarRendering.AvatarShape.UnityInterface;
using DCL.Utility;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
Expand Down Expand Up @@ -88,13 +89,28 @@ public void RegisterAvatar(AvatarBase avatarBase, ref AvatarTransformMatrixCompo

public void Dispose()
{
// Leak the resouces. Managed dispose of TransformAccessArray takes very much time.
if (DCL.Utility.ExitUtils.IsAboutToQuit)
{
return;
}

var stopwatch = ShutdownStopwatch.StartNew(nameof(AvatarTransformMatrixJobWrapper));

remoteAvatars.Complete();
stopwatch.LogStep("remoteAvatars.Complete");

remoteAvatars.Dispose();
stopwatch.LogStep("remoteAvatars.Dispose");

mainPlayerAvatar.Dispose();
stopwatch.LogStep("mainPlayerAvatar.Dispose");

if (dummyTransform != null)
{
UnityEngine.Object.Destroy(dummyTransform.gameObject);
stopwatch.LogStep("dummyTransform.Destroy");
}

disposed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,37 @@ private static void FillWithDummy(Transform[] array, int startIndex, int count,

public void Dispose()
{
// Leak the resouces. Managed dispose of TransformAccessArray takes very much time.
if (DCL.Utility.ExitUtils.IsAboutToQuit)
{
return;
}

var stopwatch = DCL.Utility.ShutdownStopwatch.StartNew(nameof(RemoteAvatarPipeline));

bonesCombined.Dispose();
stopwatch.LogStep("bonesCombined.Dispose");

matrixFromAllAvatars.Dispose();
stopwatch.LogStep("matrixFromAllAvatars.Dispose");

updateAvatar.Dispose();
stopwatch.LogStep("updateAvatar.Dispose");

Job.Dispose();
stopwatch.LogStep("job.Dispose");

if (bonesTransformAccessArray.isCreated) bonesTransformAccessArray.Dispose();
if (rootsTransformAccessArray.isCreated) rootsTransformAccessArray.Dispose();
if (bonesTransformAccessArray.isCreated)
{
bonesTransformAccessArray.Dispose();
stopwatch.LogStep("bonesTransformAccessArray.Dispose");
}

if (rootsTransformAccessArray.isCreated)
{
rootsTransformAccessArray.Dispose();
stopwatch.LogStep("rootsTransformAccessArray.Dispose");
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public static class AppArgsFlags
public const string LSD_REMOTE_AB_SERVER = "lsd-remote-ab-server";
public const string LSD_REMOTE_AB_WORLD = "lsd-remote-ab-world";

public const string NO_LIVEKIT_MODE = "no-livekit-mode";

public const string NATIVE_SHUTDOWN_STOPWATCH = "native-shutdown-stopwatch";

/// <summary>
/// Use Unity's Application.Quit() (full native teardown) on exit instead of the default hard process termination. For native debugging only.
/// </summary>
public const string SOFT_SHUTDOWN = "soft-shutdown";

public static class Multiplayer
{
public const string COMPRESSION = "compression";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,21 @@ static IMultiPool MultiPoolFactory() =>

var voiceChatRoom = new VoiceChatActivatableConnectiveRoom();

IRoomHub roomHub = new RoomHub(
localSceneDevelopment ? IConnectiveRoom.Null.INSTANCE : archipelagoIslandRoom,
gateKeeperSceneRoom,
chatRoom,
voiceChatRoom
);
IRoomHub roomHub;

if (appArgs.HasFlag(AppArgsFlags.NO_LIVEKIT_MODE))
{
roomHub = NullRoomHub.INSTANCE;
}
else
{
roomHub = new RoomHub(
localSceneDevelopment ? IConnectiveRoom.Null.INSTANCE : archipelagoIslandRoom,
gateKeeperSceneRoom,
chatRoom,
voiceChatRoom
);
}

var islandThroughputBunch = new ThroughputBufferBunch(new ThroughputBuffer(), new ThroughputBuffer());
var sceneThroughputBunch = new ThroughputBufferBunch(new ThroughputBuffer(), new ThroughputBuffer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,71 @@ public class MainSceneLoader : MonoBehaviour, ICoroutineRunner
private FileStream? singleInstanceLock;
private ErrorPopupWithRetryView? clockDesyncPopupPrefab;

private bool canShutdown;

private void Awake()
{
InitializeFlowAsync(destroyCancellationToken).Forget();
}

private void OnDestroy()
{
Shutdown();
}

private void Shutdown()
{
if (PlayerLoopHelper.IsMainThread == false)
return;

if (canShutdown == false)
return;

canShutdown = false;

var stopwatch = ShutdownStopwatch.StartNew(nameof(MainSceneLoader));

DisableAllSelectableTransitions();
stopwatch.LogStep(nameof(DisableAllSelectableTransitions));

if (dynamicWorldContainer != null)
{
foreach (IDCLGlobalPlugin plugin in dynamicWorldContainer.GlobalPlugins)
{
plugin.SafeDispose(ReportCategory.ENGINE);
stopwatch.LogStep($"GlobalPlugin {plugin.GetType().Name}");
}

if (globalWorld != null)
{
dynamicWorldContainer.RealmController.DisposeGlobalWorld();
stopwatch.LogStep("DisposeGlobalWorld");
}

dynamicWorldContainer.SafeDispose(ReportCategory.ENGINE);
stopwatch.LogStep("dynamicWorldContainer.SafeDispose");
}

if (staticContainer != null)
{
// Exclude SharedPlugins as they were disposed as they were already disposed of as `GlobalPlugins`
foreach (IDCLPlugin worldPlugin in staticContainer.ECSWorldPlugins.Except<IDCLPlugin>(staticContainer.SharedPlugins))
{
worldPlugin.SafeDispose(ReportCategory.ENGINE);
stopwatch.LogStep($"ECSWorldPlugin {worldPlugin.GetType().Name}");
}

staticContainer.SafeDispose(ReportCategory.ENGINE);
stopwatch.LogStep("staticContainer.SafeDispose");
}

bootstrapContainer?.Dispose();
stopwatch.LogStep("bootstrapContainer.Dispose");

splashScreen.Dispose();
stopwatch.LogStep("splashScreen.Dispose");

ReportHub.Log(ReportCategory.ENGINE, "OnDestroy successfully finished");
ReportHub.LogProductionInfo($"[MainSceneLoader] OnDestroy successfully finished in {stopwatch.ElapsedMilliseconds}ms");
}

private void OnApplicationQuit()
Expand All @@ -144,6 +176,11 @@ public void ApplyConfig(IAppArgs applicationParametersParser)
{
if (applicationParametersParser.TryGetValue(AppArgsFlags.ENVIRONMENT, out string? environment))
ParseEnvironment(environment!);

ExitUtils.Configure(
softShutdown: applicationParametersParser.HasFlag(AppArgsFlags.SOFT_SHUTDOWN),
nativeShutdownStopwatch: applicationParametersParser.HasFlag(AppArgsFlags.NATIVE_SHUTDOWN_STOPWATCH)
);
}

private void ParseEnvironment(string environment)
Expand All @@ -154,6 +191,9 @@ private void ParseEnvironment(string environment)

private async UniTask InitializeFlowAsync(CancellationToken ct)
{
canShutdown = true;
ExitUtils.RegisterCleanUpCandidate(new OnQuittingCleanUpCandidate(nameof(MainSceneLoader), Shutdown));

IAppArgs applicationParametersParser = new ApplicationParametersParser(
#if UNITY_EDITOR
debugSettings.AppParameters
Expand Down
Loading
Loading