From 414c46371fc8ce03627d95436ebe38561aa048c3 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Jan 2013 14:27:50 +0100 Subject: [PATCH 1/5] Call GC.Collect in a tread which removes audio stuttering when collecting --- Vocaluxe/Base/CGraphics.cs | 2 +- Vocaluxe/Base/CSongs.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index b1edd7f5..e3174afc 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -403,7 +403,7 @@ namespace Vocaluxe.Base else { _Screens[(int)_CurrentScreen].OnClose(); - GC.Collect(); + System.Threading.Thread t = new System.Threading.Thread(delegate() { GC.Collect(); }); _CurrentScreen = _NextScreen; _NextScreen = EScreens.ScreenNull; if(CBackgroundMusic.Playing) diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index f0eb5717..49ede740 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -1061,7 +1061,7 @@ namespace Vocaluxe.Base CLog.StopBenchmark(2, "Load Cover"); } CLog.StopBenchmark(1, "Load Songs "); - GC.Collect(); + Thread t = new Thread(delegate() { GC.Collect(); }); } public static void LoadCover(long WaitTime, int NumLoads) From 76dae25fe48a3560ec418c30b6e58da2f60d72c2 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Wed, 9 Jan 2013 14:51:20 +0100 Subject: [PATCH 2/5] Hitting ESC or RB will now close the search when active --- Vocaluxe/Screens/CScreenSong.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 65f9fc18..a19d16b7 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -207,6 +207,12 @@ namespace Vocaluxe.Screens case Keys.Escape: if ((CSongs.Category < 0 || _sso.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) && !_sso.Selection.PartyMode && !_SearchActive) CGraphics.FadeTo(EScreens.ScreenMain); + if (_SearchActive) + { + _SearchActive = false; + _SearchText = String.Empty; + ApplyNewSearchFilter(_SearchText); + } break; case Keys.Enter: @@ -480,7 +486,15 @@ namespace Vocaluxe.Screens return true; } - if (CSongs.Category < 0 && !_sso.Selection.PartyMode) + if (_SearchActive) + { + _SearchActive = false; + _SearchText = String.Empty; + ApplyNewSearchFilter(_SearchText); + return true; + } + + if (CSongs.Category < 0 && !_sso.Selection.PartyMode && !_SearchActive) { CGraphics.FadeTo(EScreens.ScreenMain); return true; From 66f294f5a0e0b65a17fba78edc278b1d8d230456 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 10 Jan 2013 00:29:06 +0100 Subject: [PATCH 3/5] Reverted GC.Collect changes --- Vocaluxe/Base/CGraphics.cs | 2 +- Vocaluxe/Base/CSongs.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index e3174afc..b1edd7f5 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -403,7 +403,7 @@ namespace Vocaluxe.Base else { _Screens[(int)_CurrentScreen].OnClose(); - System.Threading.Thread t = new System.Threading.Thread(delegate() { GC.Collect(); }); + GC.Collect(); _CurrentScreen = _NextScreen; _NextScreen = EScreens.ScreenNull; if(CBackgroundMusic.Playing) diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 49ede740..f0eb5717 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -1061,7 +1061,7 @@ namespace Vocaluxe.Base CLog.StopBenchmark(2, "Load Cover"); } CLog.StopBenchmark(1, "Load Songs "); - Thread t = new Thread(delegate() { GC.Collect(); }); + GC.Collect(); } public static void LoadCover(long WaitTime, int NumLoads) From 9c3f1d9ebd953be0ff69ee0cc0261cc4876bc707 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 10 Jan 2013 14:20:03 +0100 Subject: [PATCH 4/5] Only resize images in D3D when really needed --- Vocaluxe/Lib/Draw/CDirect3D.cs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index a5a5e167..6e1402a2 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -944,23 +944,27 @@ namespace Vocaluxe.Lib.Draw texture.w2 = (float)CheckForNextPowerOf2(w); texture.h2 = (float)CheckForNextPowerOf2(h); - //Create a new Bitmap with the new sizes - Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2); - //Scale the texture - Graphics g = Graphics.FromImage(bmp2); - g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; - g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; - g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); - g.Dispose(); + if (texture.w2 != bmp.Width || texture.h2 != bmp.Height) + { + //Create a new Bitmap with the new sizes + Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2); + //Scale the texture + Graphics g = Graphics.FromImage(bmp2); + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; + g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); + g.Dispose(); + bmp = bmp2; + } texture.width_ratio = 1f; texture.height_ratio = 1f; //Fill the new Bitmap with the texture data - BitmapData bmp_data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - byte[] Data = new byte[4 * bmp2.Width * bmp2.Height]; + BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, (int)texture.w2, (int)texture.h2), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + byte[] Data = new byte[4 * (int)texture.w2 * (int)texture.h2]; Marshal.Copy(bmp_data.Scan0, Data, 0, Data.Length); - bmp2.UnlockBits(bmp_data); + bmp.UnlockBits(bmp_data); //Create a new texture in the managed pool, which does not need to be recreated on a lost device //because a copy of the texture is hold in the Ram @@ -969,14 +973,13 @@ namespace Vocaluxe.Lib.Draw DataRectangle rect = t.LockRectangle(0, LockFlags.Discard); for (int i = 0; i < Data.Length; ) { - rect.Data.Write(Data, i, 4 * bmp2.Width); - i += 4 * bmp2.Width; - rect.Data.Position = rect.Data.Position - 4 * bmp2.Width; + rect.Data.Write(Data, i, 4 * (int)texture.w2); + i += 4 * (int)texture.w2; + rect.Data.Position = rect.Data.Position - 4 * (int)texture.w2; rect.Data.Position += rect.Pitch; } t.UnlockRectangle(0); - bmp2.Dispose(); bmp_data = null; // Add to Texture List From c95214ba0665411704cf7c209f60743c3d888643 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Thu, 10 Jan 2013 14:29:52 +0100 Subject: [PATCH 5/5] Fixed some memory leaks from Bitmaps --- Vocaluxe/Base/CDataBase.cs | 4 ++++ Vocaluxe/Base/CDraw.cs | 1 + Vocaluxe/Lib/Draw/CDirect3D.cs | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 8f3a6992..0019008e 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -1187,6 +1187,8 @@ namespace Vocaluxe.Base Graphics g = Graphics.FromImage(bmp); g.DrawImage(origin, new Rectangle(0, 0, w, h)); g.Dispose(); + if (origin != null) + origin.Dispose(); byte[] data = new byte[w * h * 4]; @@ -1484,6 +1486,8 @@ namespace Vocaluxe.Base Graphics g = Graphics.FromImage(bmp); g.DrawImage(origin, new Rectangle(0, 0, w, h)); g.Dispose(); + if (origin != null) + origin.Dispose(); tex = CDraw.AddTexture(bmp); byte[] data = new byte[w * h * 4]; diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 7cc74e46..06967894 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -178,6 +178,7 @@ namespace Vocaluxe.Base Bitmap bmp = new Bitmap(origin, w, h); STexture tex = _Draw.AddTexture(bmp); bmp.Dispose(); + origin.Dispose(); return tex; } diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 6e1402a2..d7aa03e6 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -881,7 +881,9 @@ namespace Vocaluxe.Lib.Draw CLog.LogError("Error loading Texture: " + TexturePath); return new STexture(-1); } - return AddTexture(bmp, TexturePath); + STexture s = AddTexture(bmp, TexturePath); + bmp.Dispose(); + return s; } CLog.LogError("Can't find File: " + TexturePath); return new STexture(-1);