From 8d7e5f4663465eec32d80d291c8728b6e89dec81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 12 Sep 2020 14:49:22 +0200 Subject: [PATCH] Fix Analyzer warning: V3022 Expression is always true. --- .../Widgets/Logic/AssetBrowserLogic.cs | 22 ++++++++++++++----- .../Widgets/Logic/Ingame/DebugMenuLogic.cs | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index d7095a914c..5b4df869b5 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic frameContainer.IsVisible = () => (currentSprites != null && currentSprites.Length > 1) || (isVideoLoaded && player != null && player.Video != null && player.Video.Frames > 1); - frameSlider = panel.Get("FRAME_SLIDER"); + frameSlider = panel.GetOrNull("FRAME_SLIDER"); if (frameSlider != null) { frameSlider.OnChange += x => @@ -183,7 +183,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic player.Stop(); else { - frameSlider.Value = 0; + if (frameSlider != null) + frameSlider.Value = 0; + currentFrame = 0; animateFrames = false; } @@ -336,15 +338,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic player.Load(prefix + filename); player.DrawOverlay = false; isVideoLoaded = true; - frameSlider.MaximumValue = (float)player.Video.Frames - 1; - frameSlider.Ticks = 0; + + if (frameSlider != null) + { + frameSlider.MaximumValue = (float)player.Video.Frames - 1; + frameSlider.Ticks = 0; + } + return true; } currentSprites = world.Map.Rules.Sequences.SpriteCache[prefix + filename]; currentFrame = 0; - frameSlider.MaximumValue = (float)currentSprites.Length - 1; - frameSlider.Ticks = currentSprites.Length; + if (frameSlider != null) + { + frameSlider.MaximumValue = (float)currentSprites.Length - 1; + frameSlider.Ticks = currentSprites.Length; + } } catch (Exception ex) { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs index fb6c1b1c31..2b5433d9e3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs @@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic showScreenMapCheckbox.OnClick = () => debugVis.ScreenMap ^= true; } - var terrainGeometryTrait = world.WorldActor.Trait(); + var terrainGeometryTrait = world.WorldActor.TraitOrDefault(); var showTerrainGeometryCheckbox = widget.GetOrNull("SHOW_TERRAIN_OVERLAY"); if (showTerrainGeometryCheckbox != null && terrainGeometryTrait != null) {