-
Notifications
You must be signed in to change notification settings - Fork 501
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
NSFontDescriptor.Create crashes #19659
Labels
Milestone
Comments
rolfbjarne
added
bug
If an issue is a bug or a pull request a bug fix
api-bindings
labels
Dec 18, 2023
This is a bug on our side, we bound this incorrectly. I'll fix it. |
Workaround: Add this to your project, and call namespace AppKit {
using System;
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;
public static class NSFontDescriptor_Extensions {
// Workaround for https://github.com/xamarin/xamarin-macios/issues/19659.
public static NSFontDescriptor? CreateWithDesign (this NSFontDescriptor fd, NSFontDescriptorSystemDesign design)
{
var nsb_design = global::AppKit.NSFontDescriptorSystemDesignExtensions.GetConstant (design);
var rv = objc_msgSend (fd.GetHandle (), Selector.GetHandle ("fontDescriptorWithDesign:"), nsb_design.GetHandle ());
GC.KeepAlive (nsb_design);
return Runtime.GetNSObject<NSFontDescriptor> (rv);
}
[DllImport ("/usr/lib/libobjc.dylib")]
static extern IntPtr objc_msgSend (IntPtr handle, IntPtr selector, IntPtr value);
}
} and then do: var fd = NSFont.SystemFontOfSize(10).FontDescriptor;
var serif = fd.CreateWithDesign(NSFontDescriptorSystemDesign.Serif);
var rounded = fd.CreateWithDesign(NSFontDescriptorSystemDesign.Rounded); |
rolfbjarne
added a commit
to rolfbjarne/xamarin-macios
that referenced
this issue
Dec 18, 2023
[NSFontDescriptor fontDescriptorWithDesign:] takes an NSString, not the enum value, so use BindAs to bind correctly. Fixes xamarin#19659.
rolfbjarne
added a commit
that referenced
this issue
Jan 2, 2024
vs-mobiletools-engineering-service2
pushed a commit
to vs-mobiletools-engineering-service2/xamarin-macios
that referenced
this issue
Jan 2, 2024
[NSFontDescriptor fontDescriptorWithDesign:] takes an NSString, not the enum value, so use BindAs to bind correctly. Fixes xamarin#19659.
vs-mobiletools-engineering-service2
pushed a commit
to vs-mobiletools-engineering-service2/xamarin-macios
that referenced
this issue
Jan 3, 2024
[NSFontDescriptor fontDescriptorWithDesign:] takes an NSString, not the enum value, so use BindAs to bind correctly. Fixes xamarin#19659.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to Reproduce
Expected Behavior
No crash, maybe return null?
Actual Behavior
Crash (that cannot be caught with try-catch)
Environment
.NET8
The text was updated successfully, but these errors were encountered: