From 36149834ab58b10b89f4a3af4b78050ae1d8d223 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 14 Jun 2019 12:32:32 +0300 Subject: [PATCH] (dfd23e93d) Code hardening to prevent Reactor UI drawing crashing the game if the reactor has been removed. I believe the crash #1636 was caused by the client failing to properly end the round (see #1518), which caused the UI to still be drawn despite the reactor being removed. --- .../Source/Items/Components/Machines/Reactor.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Reactor.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Reactor.cs index 22ad9d44d..b361c951f 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Reactor.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Reactor.cs @@ -290,6 +290,8 @@ namespace Barotrauma.Items.Components private void DrawGraph(SpriteBatch spriteBatch, GUICustomComponent container) { + if (item.Removed) { return; } + Rectangle graphArea = new Rectangle(container.Rect.X + 30, container.Rect.Y, container.Rect.Width - 30, container.Rect.Height); float maxLoad = loadGraph.Max(); @@ -359,6 +361,8 @@ namespace Barotrauma.Items.Components private void DrawFissionRateMeter(SpriteBatch spriteBatch, GUICustomComponent container) { + if (item.Removed) { return; } + Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle; spriteBatch.End(); spriteBatch.GraphicsDevice.ScissorRectangle = container.Rect; @@ -384,6 +388,8 @@ namespace Barotrauma.Items.Components private void DrawTurbineOutputMeter(SpriteBatch spriteBatch, GUICustomComponent container) { + if (item.Removed) { return; } + DrawMeter(spriteBatch, container.Rect, turbineOutputMeter, TurbineOutput, new Vector2(0.0f, 100.0f), optimalTurbineOutput, allowedTurbineOutput); } @@ -514,7 +520,7 @@ namespace Barotrauma.Items.Components Vector2 newPoint = new Vector2(currX, rect.Bottom - graph[i] * yScale); - if (graphLine == null) + if (graphLine?.Texture == null) { GUI.DrawLine(spriteBatch, prevPoint, newPoint - new Vector2(1.0f, 0), color); } @@ -530,7 +536,7 @@ namespace Barotrauma.Items.Components Vector2 lastPoint = new Vector2(rect.X, rect.Bottom - (graph[graph.Count - 1] + (graph[graph.Count - 2] - graph[graph.Count - 1]) * xOffset) * yScale); - if (graphLine == null) + if (graphLine?.Texture == null) { GUI.DrawLine(spriteBatch, prevPoint, lastPoint, color); }