Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Fix intermittent crash resizing images #2118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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