Fix crash caused by VideoPlayerWidget.DrawOverlay

Somehow this would divide by 0 on the next line, not crashing but resulting in an integer overflow on `overlayHeight`, which would crash when trying to render.
This commit is contained in:
penev92
2023-02-13 23:35:22 +02:00
committed by abcdefg30
parent 4135079290
commit 6321432d97

View File

@@ -144,6 +144,13 @@ namespace OpenRA.Mods.Common.Widgets
var videoScale = Math.Min((float)RenderBounds.Width / video.Width, RenderBounds.Height / (video.Height * AspectRatio)); var videoScale = Math.Min((float)RenderBounds.Width / video.Width, RenderBounds.Height / (video.Height * AspectRatio));
var halfRowHeight = (int)(videoScale * scale / 2 + 0.5f); var halfRowHeight = (int)(videoScale * scale / 2 + 0.5f);
// If the video is "too tightly packed" into the player and there is no room for drawing an overlay disable it.
if (halfRowHeight == 0)
{
DrawOverlay = false;
return;
}
// The overlay can be minimally stored in a 1px column which is stretched to cover the full screen // The overlay can be minimally stored in a 1px column which is stretched to cover the full screen
var overlayHeight = (int)(RenderBounds.Height * scale / halfRowHeight); var overlayHeight = (int)(RenderBounds.Height * scale / halfRowHeight);
var overlaySheetSize = new Size(1, Exts.NextPowerOf2(overlayHeight)); var overlaySheetSize = new Size(1, Exts.NextPowerOf2(overlayHeight));