From 03d1df81906dfbf9b5b6353299f494fdcd945e98 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 2 Sep 2021 09:39:19 +1000 Subject: [PATCH] Fix lobby exception (#4544) From what I could tell whenever LobbyState is entered it makes a new Lobby + CharacterSetup GUI via Startup. These events are never disposed of under Shutdown + the lobby should be null whenever we're not in LobbyState (as the control ends up disposed). The lobby == null checks could probably also be null asserts as they shouldn't be null when those methods are being called. --- Content.Client/Lobby/LobbyState.cs | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Content.Client/Lobby/LobbyState.cs b/Content.Client/Lobby/LobbyState.cs index fb85b825e3..37e4aa4bfe 100644 --- a/Content.Client/Lobby/LobbyState.cs +++ b/Content.Client/Lobby/LobbyState.cs @@ -8,11 +8,8 @@ using Content.Client.LateJoin; using Content.Client.Lobby.UI; using Content.Client.Preferences; using Content.Client.Preferences.UI; -using Content.Client.Viewport; using Content.Client.Voting; -using Content.Shared.Chat; using Content.Shared.GameTicking; -using Content.Shared.Input; using Robust.Client; using Robust.Client.Console; using Robust.Client.Input; @@ -21,7 +18,6 @@ using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; -using Robust.Shared.Input.Binding; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; @@ -45,8 +41,8 @@ namespace Content.Client.Lobby [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IVoteManager _voteManager = default!; - [ViewVariables] private CharacterSetupGui _characterSetup = default!; - [ViewVariables] private LobbyGui _lobby = default!; + [ViewVariables] private CharacterSetupGui? _characterSetup; + [ViewVariables] private LobbyGui? _lobby; public override void Startup() { @@ -55,6 +51,9 @@ namespace Content.Client.Lobby _prototypeManager); LayoutContainer.SetAnchorPreset(_characterSetup, LayoutContainer.LayoutPreset.Wide); + _lobby = new LobbyGui(_entityManager, _preferencesManager); + _userInterfaceManager.StateRoot.AddChild(_lobby); + _characterSetup.CloseButton.OnPressed += _ => { _userInterfaceManager.StateRoot.AddChild(_lobby); @@ -67,9 +66,6 @@ namespace Content.Client.Lobby _lobby?.CharacterPreview.UpdateUI(); }; - _lobby = new LobbyGui(_entityManager, _preferencesManager); - _userInterfaceManager.StateRoot.AddChild(_lobby); - LayoutContainer.SetAnchorPreset(_lobby, LayoutContainer.LayoutPreset.Wide); _chatManager.SetChatBox(_lobby.Chat); @@ -119,12 +115,22 @@ namespace Content.Client.Lobby public override void Shutdown() { _playerManager.PlayerListUpdated -= PlayerManagerOnPlayerListUpdated; - _lobby.Dispose(); - _characterSetup.Dispose(); + var gameTicker = EntitySystem.Get(); + gameTicker.InfoBlobUpdated -= UpdateLobbyUi; + gameTicker.LobbyStatusUpdated -= LobbyStatusUpdated; + gameTicker.LobbyReadyUpdated -= LobbyReadyUpdated; + gameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated; + + _lobby?.Dispose(); + _characterSetup?.Dispose(); + _lobby = null; + _characterSetup = null; } public override void FrameUpdate(FrameEventArgs e) { + if (_lobby == null) return; + var gameTicker = EntitySystem.Get(); if (gameTicker.IsGameStarted) { @@ -183,15 +189,13 @@ namespace Content.Client.Lobby private void LobbyLateJoinStatusUpdated() { + if (_lobby == null) return; _lobby.ReadyButton.Disabled = EntitySystem.Get().DisallowedLateJoin; } private void UpdateLobbyUi() { - if (_lobby == null) - { - return; - } + if (_lobby == null) return; var gameTicker = EntitySystem.Get(); @@ -218,6 +222,7 @@ namespace Content.Client.Lobby private void UpdatePlayerList() { + if (_lobby == null) return; _lobby.OnlinePlayerList.Clear(); var gameTicker = EntitySystem.Get();