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

An error occurs when running the layout example. #246

Open
kokonjac opened this issue Jan 17, 2024 · 2 comments
Open

An error occurs when running the layout example. #246

kokonjac opened this issue Jan 17, 2024 · 2 comments

Comments

@kokonjac
Copy link

go run ./macos/_examples/layout/main.go
Error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Content hugging priorities must be positive.'
*** First throw call stack:
(
        0   CoreFoundation                      0x00007ff801a4ed86 __exceptionPreprocess + 242
        1   libobjc.A.dylib                     0x00007ff801541321 objc_exception_throw + 48
        2   CoreFoundation                      0x00007ff801a4ec26 +[NSException raise:format:] + 214
        3   AppKit                              0x00007ff805ed1a52 -[NSView(NSConstraintBasedLayoutInternal) setContentHuggingPriority:forOrientation:] + 96
        4   libffi.dylib                        0x00007ff812d5d892 ffi_call_unix64 + 82
        5   main                                0x0000000100f7f4f0 runtime.zerobase + 0
)
libc++abi: terminating due to uncaught exception of type NSException
SIGABRT: abort
PC=0x7ff8018c77a2 m=0 sigcode=0
signal arrived during cgo execution
...

The cause of this error may be setting a negative priority when using Auto Layout.
But there seems to be no problem with the parameters of SetContentHuggingPriorityForOrientation.
Wondering why.

	gridView.SetContentHuggingPriorityForOrientation(appkit.LayoutPriorityDefaultHigh, appkit.LayoutConstraintOrientationHorizontal) // (750.0,0)

@hsiafan
Copy link

hsiafan commented Jan 31, 2024

I found that the data type of LayoutPriority is not correct. LayoutPriority should be 32-bit floating point number, while appkit go enum define it as 64-bit:

type LayoutPriority float64

Changing it to float 32 fixes crash for SetContentHuggingPriorityForOrientation.

@progrium
Copy link
Owner

@hsiafan Thanks for figuring this out. I thought I had tried this before, but I guess not. I would love a PR to fix the generation code on this if you're willing.

roberte3 pushed a commit to roberte3/macdriver that referenced this issue Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants