Skip to content

Commit

Permalink
Fix refcounting
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Nov 27, 2023
1 parent be0cc2d commit b0a1a1e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Dalamud/ImGuiScene/Helpers/WicEasy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public ComPtr<IWICBitmapSource> CreateBitmapSource(IStream* stream)
WICDecodeOptions.WICDecodeMetadataCacheOnDemand,
decoder.GetAddressOf()).ThrowHr();

IWICBitmapFrameDecode* result;
decoder.Get()->GetFrame(0, &result).ThrowHr();
var result = default(ComPtr<IWICBitmapSource>);
// Note: IWICBitmapSource is an ancestor of IWICBitmapFrameDecode; pointer casting is well-defined.
return (IWICBitmapSource*)result;
decoder.Get()->GetFrame(0, (IWICBitmapFrameDecode**)result.GetAddressOf()).ThrowHr();
return result;
}

/// <summary>
Expand All @@ -108,7 +108,7 @@ public ComPtr<IWICBitmapSource> CreateBitmapSource(IStream* stream)
public ComPtr<IWICBitmapSource> ConvertPixelFormat(IWICBitmapSource* source, in Guid newPixelFormat)
{
using var converter = default(ComPtr<IWICFormatConverter>);
this.Factory->CreateFormatConverter(converter.ReleaseAndGetAddressOf()).ThrowHr();
this.Factory->CreateFormatConverter(converter.GetAddressOf()).ThrowHr();
fixed (Guid* format = &newPixelFormat)
{
converter.Get()->Initialize(
Expand All @@ -120,8 +120,10 @@ public ComPtr<IWICBitmapSource> ConvertPixelFormat(IWICBitmapSource* source, in
WICBitmapPaletteType.WICBitmapPaletteTypeMedianCut).ThrowHr();
}

// Avoid increasing refcount; using a constructor of ComPtr<T> will call AddRef.
var res = default(ComPtr<IWICBitmapSource>);
// Note: IWICBitmapSource is an ancestor of IWICFormatConverter; pointer casting is well-defined.
var res = new ComPtr<IWICBitmapSource>((IWICBitmapSource*)converter.Get());
res.Attach((IWICBitmapSource*)converter.Get());
converter.Detach();
return res;
}
Expand Down

0 comments on commit b0a1a1e

Please sign in to comment.