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.
This commit is contained in:
@@ -8,11 +8,8 @@ using Content.Client.LateJoin;
|
|||||||
using Content.Client.Lobby.UI;
|
using Content.Client.Lobby.UI;
|
||||||
using Content.Client.Preferences;
|
using Content.Client.Preferences;
|
||||||
using Content.Client.Preferences.UI;
|
using Content.Client.Preferences.UI;
|
||||||
using Content.Client.Viewport;
|
|
||||||
using Content.Client.Voting;
|
using Content.Client.Voting;
|
||||||
using Content.Shared.Chat;
|
|
||||||
using Content.Shared.GameTicking;
|
using Content.Shared.GameTicking;
|
||||||
using Content.Shared.Input;
|
|
||||||
using Robust.Client;
|
using Robust.Client;
|
||||||
using Robust.Client.Console;
|
using Robust.Client.Console;
|
||||||
using Robust.Client.Input;
|
using Robust.Client.Input;
|
||||||
@@ -21,7 +18,6 @@ using Robust.Client.ResourceManagement;
|
|||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Input.Binding;
|
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -45,8 +41,8 @@ namespace Content.Client.Lobby
|
|||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||||
|
|
||||||
[ViewVariables] private CharacterSetupGui _characterSetup = default!;
|
[ViewVariables] private CharacterSetupGui? _characterSetup;
|
||||||
[ViewVariables] private LobbyGui _lobby = default!;
|
[ViewVariables] private LobbyGui? _lobby;
|
||||||
|
|
||||||
public override void Startup()
|
public override void Startup()
|
||||||
{
|
{
|
||||||
@@ -55,6 +51,9 @@ namespace Content.Client.Lobby
|
|||||||
_prototypeManager);
|
_prototypeManager);
|
||||||
LayoutContainer.SetAnchorPreset(_characterSetup, LayoutContainer.LayoutPreset.Wide);
|
LayoutContainer.SetAnchorPreset(_characterSetup, LayoutContainer.LayoutPreset.Wide);
|
||||||
|
|
||||||
|
_lobby = new LobbyGui(_entityManager, _preferencesManager);
|
||||||
|
_userInterfaceManager.StateRoot.AddChild(_lobby);
|
||||||
|
|
||||||
_characterSetup.CloseButton.OnPressed += _ =>
|
_characterSetup.CloseButton.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
_userInterfaceManager.StateRoot.AddChild(_lobby);
|
_userInterfaceManager.StateRoot.AddChild(_lobby);
|
||||||
@@ -67,9 +66,6 @@ namespace Content.Client.Lobby
|
|||||||
_lobby?.CharacterPreview.UpdateUI();
|
_lobby?.CharacterPreview.UpdateUI();
|
||||||
};
|
};
|
||||||
|
|
||||||
_lobby = new LobbyGui(_entityManager, _preferencesManager);
|
|
||||||
_userInterfaceManager.StateRoot.AddChild(_lobby);
|
|
||||||
|
|
||||||
LayoutContainer.SetAnchorPreset(_lobby, LayoutContainer.LayoutPreset.Wide);
|
LayoutContainer.SetAnchorPreset(_lobby, LayoutContainer.LayoutPreset.Wide);
|
||||||
|
|
||||||
_chatManager.SetChatBox(_lobby.Chat);
|
_chatManager.SetChatBox(_lobby.Chat);
|
||||||
@@ -119,12 +115,22 @@ namespace Content.Client.Lobby
|
|||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
_playerManager.PlayerListUpdated -= PlayerManagerOnPlayerListUpdated;
|
_playerManager.PlayerListUpdated -= PlayerManagerOnPlayerListUpdated;
|
||||||
_lobby.Dispose();
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
||||||
_characterSetup.Dispose();
|
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)
|
public override void FrameUpdate(FrameEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (_lobby == null) return;
|
||||||
|
|
||||||
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
||||||
if (gameTicker.IsGameStarted)
|
if (gameTicker.IsGameStarted)
|
||||||
{
|
{
|
||||||
@@ -183,15 +189,13 @@ namespace Content.Client.Lobby
|
|||||||
|
|
||||||
private void LobbyLateJoinStatusUpdated()
|
private void LobbyLateJoinStatusUpdated()
|
||||||
{
|
{
|
||||||
|
if (_lobby == null) return;
|
||||||
_lobby.ReadyButton.Disabled = EntitySystem.Get<ClientGameTicker>().DisallowedLateJoin;
|
_lobby.ReadyButton.Disabled = EntitySystem.Get<ClientGameTicker>().DisallowedLateJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateLobbyUi()
|
private void UpdateLobbyUi()
|
||||||
{
|
{
|
||||||
if (_lobby == null)
|
if (_lobby == null) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
||||||
|
|
||||||
@@ -218,6 +222,7 @@ namespace Content.Client.Lobby
|
|||||||
|
|
||||||
private void UpdatePlayerList()
|
private void UpdatePlayerList()
|
||||||
{
|
{
|
||||||
|
if (_lobby == null) return;
|
||||||
_lobby.OnlinePlayerList.Clear();
|
_lobby.OnlinePlayerList.Clear();
|
||||||
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user