From c5407472cd9e648563bbf1dbeb4a5462027f5e45 Mon Sep 17 00:00:00 2001 From: Isotarge <6367891+Isotarge@users.noreply.github.com> Date: Thu, 18 Oct 2018 21:21:52 +1030 Subject: [PATCH] TAStudio: Prevent exceptions with small window size --- .../CustomControls/InputRoll.Drawing.cs | 10 ++++++++++ BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs index 316afb409c..8323a367bb 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.Drawing.cs @@ -140,6 +140,11 @@ namespace BizHawk.Client.EmuHawk private void DrawData(PaintEventArgs e, List visibleColumns) { + // Prevent exceptions with small TAStudio windows + if (visibleColumns.Count == 0) + { + return; + } if (QueryItemText != null) { if (HorizontalOrientation) @@ -532,6 +537,11 @@ namespace BizHawk.Client.EmuHawk int range = Math.Min(LastVisibleRow, RowCount - 1) - startIndex + 1; int lastVisible = LastVisibleColumnIndex; int firstVisibleColumn = FirstVisibleColumn; + // Prevent exceptions with small TAStudio windows + if (firstVisibleColumn < 0) + { + return; + } if (HorizontalOrientation) { for (int i = 0, f = 0; f < range; i++, f++) diff --git a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs index ff955f51d6..b62d246e41 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/InputRoll.cs @@ -1608,7 +1608,9 @@ namespace BizHawk.Client.EmuHawk { _vBar.Maximum = Math.Max((VisibleRows - 1) * CellHeight, _vBar.Maximum); // ScrollBar.Maximum is dumb _vBar.LargeChange = (VisibleRows - 1) * CellHeight; - _hBar.LargeChange = DrawWidth / 2; + // DrawWidth can be negative if the TAStudio window is small enough + // Clamp LargeChange to 0 here to prevent exceptions + _hBar.LargeChange = Math.Max(0, DrawWidth / 2); } }