From feed39f3274d2707471b378ced33ddb631af7b6c Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Thu, 13 Oct 2022 05:37:32 +1300 Subject: [PATCH] Add null-eye warnings. (#11859) --- Content.Client/Gameplay/GameplayState.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Content.Client/Gameplay/GameplayState.cs b/Content.Client/Gameplay/GameplayState.cs index dece86421d..4d9836d830 100644 --- a/Content.Client/Gameplay/GameplayState.cs +++ b/Content.Client/Gameplay/GameplayState.cs @@ -11,6 +11,8 @@ using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Configuration; using Robust.Shared.Timing; +using Robust.Client.Player; +using Robust.Client.GameObjects; namespace Content.Client.Gameplay { @@ -19,8 +21,10 @@ namespace Content.Client.Gameplay [Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IOverlayManager _overlayManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IPlayerManager _playerMan = default!; [Dependency] private readonly IUserInterfaceManager _uiManager = default!; [Dependency] private readonly IConfigurationManager _configurationManager = default!; + [Dependency] private readonly IEntityManager _entMan = default!; protected override Type? LinkedScreenType => typeof(DefaultGameScreen); public static readonly Vector2i ViewportSize = (EyeManager.PixelsPerMeter * 21, EyeManager.PixelsPerMeter * 15); @@ -71,6 +75,22 @@ namespace Content.Client.Gameplay base.FrameUpdate(e); Viewport.Viewport.Eye = _eyeManager.CurrentEye; + + // verify that the current eye is not "null". Fuck IEyeManager. + + var ent = _playerMan.LocalPlayer?.ControlledEntity; + if (_eyeManager.CurrentEye.Position != default || ent == null) + return; + + _entMan.TryGetComponent(ent, out EyeComponent? eye); + + if (eye?.Eye == _eyeManager.CurrentEye + && _entMan.GetComponent(ent.Value).WorldPosition == default) + return; // nothing to worry about, the player is just in null space... actually that is probably a problem? + + // Currently, this shouldn't happen. This likely happened because the main eye was set to null. When this + // does happen it can create hard to troubleshoot bugs, so lets print some helpful warnings: + Logger.Warning($"Main viewport's eye is in nullspace (main eye is null?). Attached entity: {_entMan.ToPrettyString(ent.Value)}. Entity has eye comp: {eye != null}"); } protected override void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)