Skip to content

Commit 16c2ab2

Browse files
committed
fix: Fixes after testing
1 parent bdec146 commit 16c2ab2

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

Runtime/Client/LootLockerLifecycleManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace LootLocker
1111
/// </summary>
1212
public enum LifecycleManagerState
1313
{
14+
/// <summary>
15+
/// Manager is not initialized or has been destroyed - can be recreated
16+
/// </summary>
17+
Uninitialized,
18+
1419
/// <summary>
1520
/// Normal operation - services can be accessed and managed
1621
/// </summary>
@@ -132,6 +137,9 @@ private static void TeardownInstance()
132137
_instanceId = 0;
133138
_hostingGameObject = null;
134139
}
140+
141+
// Set to Uninitialized after teardown to allow recreation
142+
_state = LifecycleManagerState.Uninitialized;
135143
}
136144
}
137145

@@ -180,7 +188,7 @@ static void OnEnterPlaymodeInEditor(UnityEditor.EnterPlayModeOptions options)
180188
private bool _isInitialized = false;
181189
private bool _serviceHealthMonitoringEnabled = true;
182190
private Coroutine _healthMonitorCoroutine = null;
183-
private static LifecycleManagerState _state = LifecycleManagerState.Ready;
191+
private static LifecycleManagerState _state = LifecycleManagerState.Uninitialized;
184192
private readonly object _serviceLock = new object();
185193

186194
/// <summary>

Runtime/Client/LootLockerPresenceManager.cs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ public static IEnumerable<string> ActiveClientUlids
109109
/// </summary>
110110
public static LootLockerPresenceManager Get()
111111
{
112+
// During Unity shutdown, don't create new instances
113+
if (!Application.isPlaying)
114+
{
115+
return _instance;
116+
}
117+
112118
if (_instance != null)
113119
{
114120
return _instance;
@@ -173,7 +179,10 @@ public void SetEventSystem(LootLockerEventSystem eventSystemInstance)
173179

174180
void ILootLockerService.Reset()
175181
{
176-
_DestroyAllClients();
182+
if (!_isShuttingDown)
183+
{
184+
_DestroyAllClients();
185+
}
177186

178187
_UnsubscribeFromEvents();
179188

@@ -221,11 +230,14 @@ void ILootLockerService.HandleApplicationFocus(bool hasFocus)
221230

222231
void ILootLockerService.HandleApplicationQuit()
223232
{
224-
_isShuttingDown = true;
225-
226-
_UnsubscribeFromEvents();
227-
_DestroyAllClients();
228-
_connectedSessions?.Clear();
233+
if (!_isShuttingDown)
234+
{
235+
_isShuttingDown = true;
236+
237+
_UnsubscribeFromEvents();
238+
_DestroyAllClients();
239+
_connectedSessions?.Clear();
240+
}
229241
}
230242

231243
#endregion
@@ -814,6 +826,12 @@ public static bool IsPresenceConnected(string playerUlid = null)
814826
/// </summary>
815827
public static LootLockerPresenceConnectionStats GetPresenceConnectionStats(string playerUlid = null)
816828
{
829+
// Return empty stats during shutdown to prevent service access
830+
if (!Application.isPlaying)
831+
{
832+
return new LootLockerPresenceConnectionStats();
833+
}
834+
817835
var instance = Get();
818836
if (instance == null) return new LootLockerPresenceConnectionStats();
819837

@@ -953,7 +971,14 @@ private void _DestroyAllClients()
953971
_connectingClients.Clear();
954972
}
955973

956-
// Destroy all clients outside the lock
974+
// During Unity shutdown, don't destroy objects manually to avoid conflicts with LifecycleManager
975+
if (!Application.isPlaying || _isShuttingDown)
976+
{
977+
// Just clear the collections, let Unity handle object destruction during shutdown
978+
return;
979+
}
980+
981+
// Destroy all clients outside the lock (only during normal operation)
957982
foreach (var client in clientsToDestroy)
958983
{
959984
if (client != null)
@@ -1353,14 +1378,22 @@ private LootLockerPresenceClient _GetPresenceClientForUlid(string playerUlid)
13531378

13541379
private void OnDestroy()
13551380
{
1381+
// During Unity shutdown, avoid any complex operations
1382+
if (!Application.isPlaying)
1383+
{
1384+
return;
1385+
}
1386+
13561387
if (!_isShuttingDown)
13571388
{
13581389
_isShuttingDown = true;
13591390
_UnsubscribeFromEvents();
13601391

1392+
// Only destroy clients if we're not in Unity shutdown
13611393
_DestroyAllClients();
13621394
}
13631395

1396+
// Skip lifecycle manager operations during shutdown
13641397
if(!LootLockerLifecycleManager.IsReady) return;
13651398

13661399
// Only unregister if the LifecycleManager exists and we're actually registered

0 commit comments

Comments
 (0)