From c0e6922dd407d9b2a99de0eef9eccf9bb97374ae Mon Sep 17 00:00:00 2001 From: Ritchie Frodomar Date: Sun, 2 Jun 2024 13:26:51 -0400 Subject: [PATCH] Fix race condition caused by Unity being weird --- Assets/Scripts/UI/Shell/Desktop.cs | 12 +++++++--- .../Scripts/UI/Windowing/TabbedToolManager.cs | 23 ++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Assets/Scripts/UI/Shell/Desktop.cs b/Assets/Scripts/UI/Shell/Desktop.cs index 6e841d06..be11c65a 100644 --- a/Assets/Scripts/UI/Shell/Desktop.cs +++ b/Assets/Scripts/UI/Shell/Desktop.cs @@ -17,6 +17,7 @@ using UnityEngine.UI; using UnityExtensions; using Utility; using System.Threading.Tasks; +using Cysharp.Threading.Tasks; namespace UI.Shell { @@ -70,10 +71,9 @@ namespace UI.Shell gameManager.UriManager.RegisterSchema("shell", new ShellUriSchemeHandler(this)); this.UpdateUserDisplay(); - await this.toolManager.StartFirstTool(); Show(); } - + private void OnDisable() { gameManager.UriManager.UnregisterSchema("web"); @@ -82,9 +82,15 @@ namespace UI.Shell Hide(); } - private void Start() + private async void Start() { + // Prevents a race condition since OnEnable is async + while (loginProcess == null) + await Task.Yield(); + this.currentWorkspace = playerHolder.Value.UiManager.WindowManager.DefineWorkspace(this.workspaceArea); + + await toolManager.StartFirstTool(); } /// diff --git a/Assets/Scripts/UI/Windowing/TabbedToolManager.cs b/Assets/Scripts/UI/Windowing/TabbedToolManager.cs index cddbd62c..c4402ab0 100644 --- a/Assets/Scripts/UI/Windowing/TabbedToolManager.cs +++ b/Assets/Scripts/UI/Windowing/TabbedToolManager.cs @@ -32,34 +32,29 @@ namespace UI.Windowing private TabbedTool? currentTool; private ITile tile; private GameManager gameManager = null!; - + /// protected override void Awake() { gameManager = GameManager.Instance; - + this.AssertAllFieldsAreSerialized(typeof(TabbedToolManager)); this.MustGetComponent(out tile); this.MustGetComponentInParent(out shell); this.tile.WindowClosed += OnTileClosed; - base.Awake(); - } - - /// - protected override void Start() - { - base.Start(); this.tools.Clear(); - + // Really cursed bullshit linq code that I'd never get CAUGHT DEAD writing for trixel... // that makes the terminal always show up first no matter what. this.tools.AddRange(this.gameManager.AvailableTools - .OrderByDescending(x=>x.Equals(terminal)) - .ThenBy(x=>x.Program.WindowTitle) - .Select(x=>new TabbedTool(x, shell))); + .OrderByDescending(x => x.Equals(terminal)) + .ThenBy(x => x.Program.WindowTitle) + .Select(x => new TabbedTool(x, shell))); this.BuildDock(); + + base.Awake(); } private void BuildDock() @@ -81,7 +76,7 @@ namespace UI.Windowing }); } } - + private void MustGetToolGui(out T behaviour) where T : MonoBehaviour { if (this.tile.ActiveContent is not RectTransformContentPanel contentPanel)