Skip to content

Commit a7935c0

Browse files
committed
Fix crash in Picker init when selection is nil
1 parent 1e1d74a commit a7935c0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Sources/GtkBackend/GtkBackend.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ public final class GtkBackend: AppBackend {
754754
)
755755

756756
picker.notifySelected = { picker, _ in
757-
if picker.selected == GTK_INVALID_LIST_POSITION {
757+
if picker.selected == Int(Int32(bitPattern: GTK_INVALID_LIST_POSITION)) {
758758
onChange(nil)
759759
} else {
760760
onChange(picker.selected)
@@ -764,9 +764,8 @@ public final class GtkBackend: AppBackend {
764764

765765
public func setSelectedOption(ofPicker picker: Widget, to selectedOption: Int?) {
766766
let picker = picker as! DropDown
767-
if let selectedOption, selectedOption != picker.selected {
768-
// Don't to assign GTK_INVALID_LIST_POSITION to picker.selected as it leads to crash
769-
picker.selected = selectedOption
767+
if selectedOption != picker.selected {
768+
picker.selected = selectedOption ?? Int(Int32(bitPattern: GTK_INVALID_LIST_POSITION))
770769
}
771770
}
772771

0 commit comments

Comments
 (0)