From d7c3f3fa9da5552e361af7ffff287491dccef840 Mon Sep 17 00:00:00 2001 From: hsgwon Date: Fri, 5 Jul 2019 11:42:39 +0900 Subject: [PATCH] [ImageUtil] Fix crash issue (#919) * [MediaController] Fix crash issue caused by GC memory collecting. --- .../ImageUtil/ImageDecoder.cs | 15 ++++++++++----- .../Interop/Interop.ImageUtil.Decode.cs | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs b/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs index 4e47ed705..81824ec70 100644 --- a/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs +++ b/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs @@ -126,7 +126,6 @@ namespace Tizen.Multimedia.Util var pathPtr = Marshal.StringToHGlobalAnsi(inputFilePath); try { - SetInputPath(Handle, pathPtr).ThrowIfFailed("Failed to set input file path for decoding"); return await DecodeAsync(); } @@ -204,20 +203,26 @@ namespace Tizen.Multimedia.Util private IEnumerable RunDecoding() { - IntPtr outBuffer = IntPtr.Zero; + IntPtr outBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); + Marshal.WriteIntPtr(outBuffer, IntPtr.Zero); try { - SetOutputBuffer(Handle, out outBuffer).ThrowIfFailed("Failed to decode given image"); + SetOutputBuffer(Handle, outBuffer).ThrowIfFailed("Failed to decode given image"); DecodeRun(Handle, out var width, out var height, out var size). ThrowIfFailed("Failed to decode"); - yield return new BitmapFrame(outBuffer, width, height, (int)size); + yield return new BitmapFrame(Marshal.ReadIntPtr(outBuffer), width, height, (int)size); } finally { - LibcSupport.Free(outBuffer); + if (Marshal.ReadIntPtr(outBuffer) != IntPtr.Zero) + { + LibcSupport.Free(Marshal.ReadIntPtr(outBuffer)); + } + + Marshal.FreeHGlobal(outBuffer); } } diff --git a/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Decode.cs b/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Decode.cs index f7636c679..938db125d 100644 --- a/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Decode.cs +++ b/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Decode.cs @@ -39,7 +39,7 @@ internal static partial class Interop internal static extern ImageUtilError SetInputBuffer(ImageDecoderHandle handle, byte[] srcBuffer, ulong srcSize); [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_output_buffer")] - internal static extern ImageUtilError SetOutputBuffer(ImageDecoderHandle handle, out IntPtr dstBuffer); + internal static extern ImageUtilError SetOutputBuffer(ImageDecoderHandle handle, IntPtr dstBuffer); [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_colorspace")] internal static extern ImageUtilError SetColorspace(ImageDecoderHandle handle, ImageColorSpace colorspace); -- 2.34.1