Skip to content

Commit 0d74e9e

Browse files
committed
Fix Gtk3Backend button-press-event signal handler crash
The Gtk 3 docs say that the signal handler should take GdkEventButton as a value, but in reality it seems that we have to take it as a pointer. To reproduce the issue, double click any clickable view (e.g. a TextField) in a Gtk3Backend app. The crash occurs because the incorrect argument size causes the unmanaged SignalBox pointer to be some random pointer. Why the crash didn't occur on non Rocky Linux platforms still evades me.
1 parent 84015e4 commit 0d74e9e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/Gtk3/Widgets/Widget.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ open class Widget: GObject {
2424
}
2525

2626
func didMoveToParent() {
27+
// The Gtk3 docs claim that this handler should take GdkEventButton as a
28+
// value, but that leads to crashes on Rocky Linux. These crashes are
29+
// fixed by instead taking the event as a pointer. I've confirmed that
30+
// this also leads to correct functionality on Rocky Linux (with correct
31+
// mouse coordinates etc). The weird part is that this code works
32+
// perfectly on macOS and Ubuntu with and without indirection. Huh??
33+
//
34+
// The docs: https://docs.gtk.org/gtk3/signal.Widget.button-press-event.html
2735
let handler1:
2836
@convention(c) (
2937
UnsafeMutableRawPointer,
30-
GdkEventButton,
38+
UnsafePointer<GdkEventButton>,
3139
UnsafeMutableRawPointer
3240
) -> Void = { _, value1, data in
33-
SignalBox1<GdkEventButton>.run(data, value1)
41+
SignalBox1<GdkEventButton>.run(data, value1.pointee)
3442
}
3543

3644
addSignal(

0 commit comments

Comments
 (0)