mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Peek]Fix crash while loading thumbnails for small pngs (#28190)
This commit is contained in:
@@ -18,6 +18,7 @@ namespace Peek.FilePreviewer.Previewers.Helpers
|
|||||||
public static async Task<BitmapSource> GetBitmapFromHBitmapAsync(IntPtr hbitmap, bool isSupportingTransparency, CancellationToken cancellationToken)
|
public static async Task<BitmapSource> GetBitmapFromHBitmapAsync(IntPtr hbitmap, bool isSupportingTransparency, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Bitmap? bitmap = null;
|
Bitmap? bitmap = null;
|
||||||
|
Bitmap? tempBitmapForDeletion = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -32,7 +33,8 @@ namespace Peek.FilePreviewer.Previewers.Helpers
|
|||||||
|
|
||||||
var transparentBitmap = new Bitmap(bitmapData.Width, bitmapData.Height, bitmapData.Stride, PixelFormat.Format32bppArgb, bitmapData.Scan0);
|
var transparentBitmap = new Bitmap(bitmapData.Width, bitmapData.Height, bitmapData.Stride, PixelFormat.Format32bppArgb, bitmapData.Scan0);
|
||||||
|
|
||||||
bitmap.Dispose();
|
// Can't dispose of original bitmap yet as that causes crashes on png files. Saving it for later disposal after saving to stream.
|
||||||
|
tempBitmapForDeletion = bitmap;
|
||||||
bitmap = transparentBitmap;
|
bitmap = transparentBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +55,7 @@ namespace Peek.FilePreviewer.Previewers.Helpers
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
bitmap?.Dispose();
|
bitmap?.Dispose();
|
||||||
|
tempBitmapForDeletion?.Dispose();
|
||||||
|
|
||||||
// delete HBitmap to avoid memory leaks
|
// delete HBitmap to avoid memory leaks
|
||||||
NativeMethods.DeleteObject(hbitmap);
|
NativeMethods.DeleteObject(hbitmap);
|
||||||
|
|||||||
Reference in New Issue
Block a user