From 3b181ba6e4dedfea7dcfc1d226d6c00c3aab09f3 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 22 Jul 2022 16:04:07 -0400 Subject: [PATCH] DisplayManager - fix crashes when setting absurdly large padding values (fixes #3321) --- .../DisplayManager/DisplayManagerBase.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs index 4c4baf9ae0..1811193be2 100644 --- a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs +++ b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs @@ -317,6 +317,11 @@ namespace BizHawk.Client.Common Size size = chainInSize; size.Width += padding.Left + padding.Right; size.Height += padding.Top + padding.Bottom; + + //in case the user requested so much padding that the dimensions are now negative, just turn it to something small + if (size.Width < 1) size.Width = 1; + if (size.Height < 1) size.Height = 1; + FinalPresentation fPadding = new FinalPresentation(size); chain.AddFilter(fPadding, "padding"); fPadding.GuiRenderer = _renderer; @@ -619,6 +624,11 @@ namespace BizHawk.Client.Common bufferWidth += padding.Horizontal; bufferHeight += padding.Vertical; + //in case the user requested so much padding that the dimensions are now negative, just turn it to something small. + if (virtualWidth < 1) virtualWidth = 1; + if (virtualHeight < 1) virtualHeight = 1; + if (bufferWidth < 1) bufferWidth = 1; + if (bufferHeight < 1) bufferHeight = 1; // old stuff var fvp = new FakeVideoProvider @@ -833,6 +843,10 @@ namespace BizHawk.Client.Common vw += padding.Horizontal; vh += padding.Vertical; + //in case the user requested so much padding that the dimensions are now negative, just turn it to something small. + if (vw < 1) vw = 1; + if (vh < 1) vh = 1; + BitmapBuffer bb = null; Texture2d videoTexture = null; if (!simulate)