From ecd678117eb6ba295258b9139d1163fad796a4cb Mon Sep 17 00:00:00 2001 From: Artyom Sovetnikov Date: Tue, 18 Feb 2020 17:06:19 +0300 Subject: [PATCH 1/3] support disable domain reload When domain reload is disabled, re-initialization is required when entering play mode; otherwise, pending tasks will leak between play mode sessions. --- Assets/UniRx.Async/PlayerLoopHelper.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Assets/UniRx.Async/PlayerLoopHelper.cs b/Assets/UniRx.Async/PlayerLoopHelper.cs index 326edf7..8242167 100644 --- a/Assets/UniRx.Async/PlayerLoopHelper.cs +++ b/Assets/UniRx.Async/PlayerLoopHelper.cs @@ -96,21 +96,31 @@ namespace UniRx.Async #endif }; - var dest = new PlayerLoopSystem[loopSystem.subSystemList.Length + 2]; - Array.Copy(loopSystem.subSystemList, 0, dest, 2, loopSystem.subSystemList.Length); + var source = loopSystem.subSystemList // Remove items form previous initializations. + .Where(ls => ls.type != loopRunnerYieldType && ls.type != loopRunnerType).ToArray(); + var dest = new PlayerLoopSystem[source.Length + 2]; + Array.Copy(source, 0, dest, 2, source.Length); dest[0] = yieldLoop; dest[1] = runnerLoop; return dest; } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] - static void Init() + static void Init () { // capture default(unity) sync-context. unitySynchronizationContetext = SynchronizationContext.Current; mainThreadId = Thread.CurrentThread.ManagedThreadId; +#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER + // When domain reload is disabled, re-initialization is required when entering play mode; + // otherwise, pending tasks will leak between play mode sessions. + var domainReloadDisabled = UnityEditor.EditorSettings.enterPlayModeOptionsEnabled && + UnityEditor.EditorSettings.enterPlayModeOptions.HasFlag(UnityEditor.EnterPlayModeOptions.DisableDomainReload); + if (!domainReloadDisabled && runners != null) return; +#else if (runners != null) return; // already initialized +#endif var playerLoop = #if UNITY_2019_3_OR_NEWER From 9c257e44f0251812f4400d69084bce1ac6e9ed3e Mon Sep 17 00:00:00 2001 From: Artyom Sovetnikov Date: Tue, 18 Feb 2020 17:19:10 +0300 Subject: [PATCH 2/3] fix formatting --- Assets/UniRx.Async/PlayerLoopHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/UniRx.Async/PlayerLoopHelper.cs b/Assets/UniRx.Async/PlayerLoopHelper.cs index 8242167..1a67a66 100644 --- a/Assets/UniRx.Async/PlayerLoopHelper.cs +++ b/Assets/UniRx.Async/PlayerLoopHelper.cs @@ -106,7 +106,7 @@ namespace UniRx.Async } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] - static void Init () + static void Init() { // capture default(unity) sync-context. unitySynchronizationContetext = SynchronizationContext.Current; From 9db6482f0a6dedeb70470ab19bdcb53f9d774c25 Mon Sep 17 00:00:00 2001 From: Artyom Sovetnikov Date: Tue, 18 Feb 2020 17:20:13 +0300 Subject: [PATCH 3/3] fix typo --- Assets/UniRx.Async/PlayerLoopHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/UniRx.Async/PlayerLoopHelper.cs b/Assets/UniRx.Async/PlayerLoopHelper.cs index 1a67a66..34ee487 100644 --- a/Assets/UniRx.Async/PlayerLoopHelper.cs +++ b/Assets/UniRx.Async/PlayerLoopHelper.cs @@ -96,7 +96,7 @@ namespace UniRx.Async #endif }; - var source = loopSystem.subSystemList // Remove items form previous initializations. + var source = loopSystem.subSystemList // Remove items from previous initializations. .Where(ls => ls.type != loopRunnerYieldType && ls.type != loopRunnerType).ToArray(); var dest = new PlayerLoopSystem[source.Length + 2]; Array.Copy(source, 0, dest, 2, source.Length);