From 8ed62df8e230593fdb78715ced6c8ef2e419b8ca Mon Sep 17 00:00:00 2001 From: stax76 Date: Sat, 2 Apr 2022 11:15:04 +0200 Subject: [PATCH] workaround not reproducible logo drawing crash --- docs/Changelog.md | 2 ++ src/Misc/CorePlayer.cs | 51 ++++++++++++++++++++++++------------------ src/Misc/Settings.cs | 1 + 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 580757a..5095034 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -11,6 +11,8 @@ - mpv.net specific commands, the command palette, auto-play property and various other things are documented in the manual. - The action used for the right mouse button can be configured. +- Workaround not reproducible logo drawing crash. +- MediaInfo 22.03 5.7.0.0 Stable (2022-03-09) diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index eb98d50..68f76bb 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -1330,34 +1330,41 @@ KP1 script-binding delete_current_file/confirm public void ShowLogo() { - if (MainForm.Instance is null) + if (MainForm.Instance == null || App.Settings.LogoCrash) return; - bool december = DateTime.Now.Month == 12; - - Rectangle cr = MainForm.Instance.ClientRectangle; - int len = Convert.ToInt32(cr.Height / (december ? 4.5 : 5)); - - if (len == 0) - return; - - using (Bitmap bmp = new Bitmap(len, len)) + try { - using (Graphics gx = Graphics.FromImage(bmp)) + bool december = DateTime.Now.Month == 12; + + Rectangle cr = MainForm.Instance.ClientRectangle; + int len = Convert.ToInt32(cr.Height / (december ? 4.5 : 5)); + + if (len == 0) + return; + + using (Bitmap bmp = new Bitmap(len, len)) { - gx.InterpolationMode = InterpolationMode.HighQualityBicubic; - gx.Clear(Color.Black); - Rectangle rect = new Rectangle(0, 0, len, len); - Bitmap bmp2 = december ? Properties.Resources.mpvnet_santa : Properties.Resources.mpvnet; - gx.DrawImage(bmp2, rect); - BitmapData bd = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb); - int x = Convert.ToInt32((cr.Width - len) / (december ? 1.95 : 2)); - int y = Convert.ToInt32((cr.Height - len) / 2.0 * (december ? 0.85 : 0.9)); - CommandV("overlay-add", "0", $"{x}", $"{y}", "&" + bd.Scan0.ToInt64().ToString(), "0", "bgra", bd.Width.ToString(), bd.Height.ToString(), bd.Stride.ToString()); - bmp.UnlockBits(bd); - IsLogoVisible = true; + using (Graphics gx = Graphics.FromImage(bmp)) + { + gx.InterpolationMode = InterpolationMode.HighQualityBicubic; + gx.Clear(Color.Black); + Rectangle rect = new Rectangle(0, 0, len, len); + Bitmap bmp2 = december ? Properties.Resources.mpvnet_santa : Properties.Resources.mpvnet; + gx.DrawImage(bmp2, rect); + BitmapData bd = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb); + int x = Convert.ToInt32((cr.Width - len) / (december ? 1.95 : 2)); + int y = Convert.ToInt32((cr.Height - len) / 2.0 * (december ? 0.85 : 0.9)); + CommandV("overlay-add", "0", $"{x}", $"{y}", "&" + bd.Scan0.ToInt64().ToString(), "0", "bgra", bd.Width.ToString(), bd.Height.ToString(), bd.Stride.ToString()); + bmp.UnlockBits(bd); + IsLogoVisible = true; + } } } + catch (Exception) + { + App.Settings.LogoCrash = true; + } } string GetLanguage(string id) diff --git a/src/Misc/Settings.cs b/src/Misc/Settings.cs index 38d707b..8dc7e19 100644 --- a/src/Misc/Settings.cs +++ b/src/Misc/Settings.cs @@ -15,6 +15,7 @@ namespace mpvnet public class AppSettings { public bool InputDefaultBindingsFixApplied; + public bool LogoCrash; public bool ShowMenuFixApplied; public int Volume = 70; public List RecentFiles = new List();