From c690c1b637ff90c8ec6ef54e1339e7b37cd67840 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 26 May 2021 22:48:07 -0700 Subject: [PATCH] Don't have `using` for generic bclim write Line 243: using calls Close() in the dispose implementation, which then closes the underlying MemoryStream. Fixes #486 Ideally, this should be rewritten, but it's old code and works for what it needs to do. Removed the useless `ref` inputs, as the reference is never replaced. --- pk3DS.Core/CTR/Images/BCLIM.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pk3DS.Core/CTR/Images/BCLIM.cs b/pk3DS.Core/CTR/Images/BCLIM.cs index 1eefdea..f8ac070 100644 --- a/pk3DS.Core/CTR/Images/BCLIM.cs +++ b/pk3DS.Core/CTR/Images/BCLIM.cs @@ -78,14 +78,14 @@ public static byte[] IMGToBCLIM(Image img, char fc) if (fc == 'X') { - Write16BitColorPalette(mBitmap, ref ms); + Write16BitColorPalette(mBitmap, ms); } else { bclimformat = Convert.ToInt16(fc.ToString(), 16); try { - WriteGeneric(bclimformat, mBitmap, ref ms); + WriteGeneric(bclimformat, mBitmap, ms); } catch (Exception e) { @@ -154,7 +154,7 @@ public static Image MakeBMP(string path, bool autosave = false, bool crop = true } // BCLIM Data Writing - public static int Write16BitColorPalette(Bitmap img, ref MemoryStream ms) + public static int Write16BitColorPalette(Bitmap img, MemoryStream ms) { using Stream pixelcolors = new MemoryStream(); using BinaryWriter bz = new BinaryWriter(pixelcolors); @@ -238,9 +238,9 @@ public static int Write16BitColorPalette(Bitmap img, ref MemoryStream ms) return 7; } - public static void WriteGeneric(int format, Bitmap img, ref MemoryStream ms, bool rectangle = true) + public static void WriteGeneric(int format, Bitmap img, MemoryStream ms, bool rectangle = true) { - using var bz = new BinaryWriter(ms); + var bz = new BinaryWriter(ms); // no using, as we need to reuse ms later. bz.Write(GetPixelData(img, format, rectangle)); bz.Flush(); }