EventController.get_current_event() causes SEGFAULT
While porting some code from GTK+ 3 to GTK 4 I ran into the following issue: calling EventController.get_current_event in a controller signal handler causes the application to crash.
Minimal example:
"""
This little program shows how one can crasg a PyGObject
application by simply requesting the latest event from
a controller.
1. Start this script
2. Click on the window
"""
import gi
gi.require_version("Gtk", '4.0')
from gi.repository import Gtk
def on_pressed(ctrl, n_press, x, y):
# This will cause a SEGFAULT:
print(ctrl.get_current_event())
def window():
ctrl = Gtk.GestureClick()
ctrl.connect("pressed", on_pressed)
w = Gtk.Window.new()
w.add_controller(ctrl)
w.show()
return w
def main():
app = Gtk.Application.new("org.gaphor.gaphas.ClickTest", 0)
def activate(app):
win = window()
app.add_window(win)
app.connect("activate", activate)
app.run()
if __name__ == "__main__":
main()
Output:
/home/arjan/Development/gaphas/test_get_current_event.py:19: Warning: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
print(ctrl.get_current_event())
/home/arjan/Development/gaphas/test_get_current_event.py:19: Warning: g_object_is_floating: assertion 'G_IS_OBJECT (object)' failed
print(ctrl.get_current_event())
/home/arjan/Development/gaphas/test_get_current_event.py:19: Warning: g_object_ref_sink: assertion 'G_IS_OBJECT (object)' failed
print(ctrl.get_current_event())
** (python:27655): CRITICAL **: 16:13:08.868: pygobject_register_wrapper: assertion 'PyObject_TypeCheck(self, &PyGObject_Type)' failed
<gi.repository.Gdk.ButtonEvent object at 0x7f5594557ee0>
[1] 27655 segmentation fault (core dumped) python test_get_current_event.py