From 65864145e6be5c40fb3eeda23fff24e976567838 Mon Sep 17 00:00:00 2001 From: mewlist Date: Fri, 23 Feb 2024 01:33:51 +0900 Subject: [PATCH 1/3] SceneContextLoader progression --- Runtime/Context/SceneContextLoader.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Runtime/Context/SceneContextLoader.cs b/Runtime/Context/SceneContextLoader.cs index 2b82506..e469c4c 100644 --- a/Runtime/Context/SceneContextLoader.cs +++ b/Runtime/Context/SceneContextLoader.cs @@ -17,6 +17,7 @@ public class SceneContextLoader : MonoBehaviour, IAsyncDisposable private IContext Context { get; set; } private List ChildSceneContexts { get; } = new(); public IReadOnlyList ReadonlyChildSceneContexts => ChildSceneContexts; + public float Progression => SceneLoader.Progression; private TaskQueue TaskQueue { get; } = new(); private bool Disposed { get; set; } From 7f8163bdf2b79c0413019fa970e818afb98fd70f Mon Sep 17 00:00:00 2001 From: mewlist Date: Fri, 23 Feb 2024 01:34:18 +0900 Subject: [PATCH 2/3] AutoContextLoader runs when it enalbed --- Runtime/Context/AutoContextLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Context/AutoContextLoader.cs b/Runtime/Context/AutoContextLoader.cs index 21a0f6a..6ed7b49 100644 --- a/Runtime/Context/AutoContextLoader.cs +++ b/Runtime/Context/AutoContextLoader.cs @@ -26,7 +26,7 @@ public async Task Construct(IContext context) public async Task AfterInject() { // If this context is loaded from child scene context, do not load child scene contexts. - if (Context.IsReverseLoaded) return; + if (!enabled || Context.IsReverseLoaded) return; foreach (var sceneContext in sceneContexts) await Context.SceneContextLoader.LoadAsync(sceneContext, active: true); From c65319f9fddc4f4eb9bd0c2aee80d1b9ca65598e Mon Sep 17 00:00:00 2001 From: mewlist Date: Fri, 23 Feb 2024 01:35:34 +0900 Subject: [PATCH 3/3] Fix race condition in scene context loading --- .../Context/ParentSceneContextRequirement.cs | 4 ++-- Runtime/Context/SceneContext.cs | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Runtime/Context/ParentSceneContextRequirement.cs b/Runtime/Context/ParentSceneContextRequirement.cs index 5cf0c40..a1cdf95 100644 --- a/Runtime/Context/ParentSceneContextRequirement.cs +++ b/Runtime/Context/ParentSceneContextRequirement.cs @@ -18,8 +18,8 @@ public async Task ResolveParentContext(SceneContext current) #if UNITY_EDITOR using var scope = new ParentContextLoadingScope(gameObject.scene); - handle = await UnifiedSceneLoader.LoadAsync(Scene, destroyCancellationToken); - var scene = await handle.GetScene(); + handle = UnifiedSceneLoader.LoadAsync(Scene); + var scene = await handle.GetScene(destroyCancellationToken); var sceneContext = scene.FindFirstObjectByType(); if (!sceneContext) diff --git a/Runtime/Context/SceneContext.cs b/Runtime/Context/SceneContext.cs index c0b1a9e..01dd7da 100644 --- a/Runtime/Context/SceneContext.cs +++ b/Runtime/Context/SceneContext.cs @@ -112,14 +112,26 @@ var gameObjectContexts = GetComponentsUnderContext() .Where(x => x.enabled); - await ContextInternal.RawContainer.GenerateResolvers(); + try + { + await ContextInternal.RawContainer.GenerateResolvers(); - await Task.WhenAll(injectableComponents.Select(x - => ContextInternal.RawContainer.InjectIntoAsync(x).AsTask())); + await Task.WhenAll(injectableComponents.Select(x + => ContextInternal.RawContainer.InjectIntoAsync(x).AsTask())); - while (InjectionProcessing) - await TaskHelper.NextFrame(destroyCancellationToken); + while (InjectionProcessing) + await TaskHelper.NextFrame(destroyCancellationToken); + } + catch (Exception _) + { + if (ParentContext is not null && !ParentContext.Loaded) + { + Debug.LogWarning("Parent context is not loaded. Shutdown SceneContext."); + await Shutdown(); + return; + } + } using (new ContextSpaceScope(this)) { foreach (var gameObjectContext in gameObjectContexts)