Skip to content

Commit

Permalink
Merge pull request #2118 from cwensley/curtis/mac-fix-intermittent-re…
Browse files Browse the repository at this point in the history
…sizing-image-crash

Mac: Fix intermittent crash resizing images
  • Loading branch information
cwensley authored Jan 21, 2022
2 parents a83127a + 629b806 commit 6fda483
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/Eto.Mac/Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ public static T GetNSObject<T>(IntPtr ptr)

[DllImport(LIBOBJC_DYLIB, EntryPoint = "objc_msgSendSuper")]
public static extern IntPtr IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr_ref_CGPoint(IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2, IntPtr arg3, ref CGPoint arg4);
[DllImport (LIBOBJC_DYLIB, EntryPoint="objc_msgSend")]
public extern static void void_objc_msgSend_IntPtr_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2);

[DllImport(LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")]
public extern static void void_objc_msgSend_IntPtr_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2);

[DllImport(LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool bool_objc_msgSend_CGRect_CGRect_UIntPtr_nfloat_bool_IntPtr(IntPtr receiver, IntPtr selector, CGRect arg1, CGRect arg2, UIntPtr arg3, nfloat arg4, [MarshalAs(UnmanagedType.I1)] bool arg5, IntPtr arg6);

}
}

12 changes: 9 additions & 3 deletions src/Eto.Mac/NSImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public static NSImage Resize(this NSImage image, CGSize newsize, ImageInterpolat
return newimage;
}

// remove when XamMac supports null for draw hint dictionary
static NSDictionary DrawHints = new NSDictionary();
#if XAMMAC
static IntPtr selDrawInRect_FromRect_Operation_Fraction_RespectFlipped_Hints_Handle = Selector.GetHandle("drawInRect:fromRect:operation:fraction:respectFlipped:hints:");
#endif

public static NSImageRep Resize(this NSImageRep image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default, CGSize? imageSize = null)
{
Expand All @@ -62,7 +63,12 @@ public static NSImageRep Resize(this NSImageRep image, CGSize newsize, ImageInte
NSGraphicsContext.GlobalSaveGraphicsState();
NSGraphicsContext.CurrentContext = graphics;
graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG();
image.DrawInRect(new CGRect(CGPoint.Empty, newrep.Size), CGRect.Empty, NSCompositingOperation.SourceOver, 1f, true, DrawHints);
#if XAMMAC
// Xamarin.Mac doesn't allow null for hints, remove this when it does.
Messaging.bool_objc_msgSend_CGRect_CGRect_UIntPtr_nfloat_bool_IntPtr(image.Handle, selDrawInRect_FromRect_Operation_Fraction_RespectFlipped_Hints_Handle, new CGRect(CGPoint.Empty, newrep.Size), CGRect.Empty, (UIntPtr)(ulong)NSCompositingOperation.SourceOver, 1f, true, IntPtr.Zero);
#else
image.DrawInRect(new CGRect(CGPoint.Empty, newrep.Size), CGRect.Empty, NSCompositingOperation.SourceOver, 1f, true, null);
#endif
NSGraphicsContext.GlobalRestoreGraphicsState();
return newrep;
}
Expand Down

0 comments on commit 6fda483

Please sign in to comment.