An error occurs when running the layout example.
kokonjac opened this issue · 3 comments
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)
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.
@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.
Turns out we were treating all floats the same, but it's been fixed. Thanks all!