Description
Bug summary
When hovering over a graph created with a GTK4 backend, it causes a segmentation fault.
Code for reproduction
import matplotlib.pyplot as plt
plt.plot(1, 2)
plt.show()
Actual outcome
A graph window shows up. However, when you hover your mouse over the window, some cryptic errors are thrown, and then it causes a segmentation fault:
/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backends/backend_gtk4.py:160: Warning: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
guiEvent=controller.get_current_event(),
/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backends/backend_gtk4.py:160: Warning: g_object_is_floating: assertion 'G_IS_OBJECT (object)' failed
guiEvent=controller.get_current_event(),
/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backends/backend_gtk4.py:160: Warning: g_object_ref_sink: assertion 'G_IS_OBJECT (object)' failed
guiEvent=controller.get_current_event(),
** (python3:238467): CRITICAL **: 20:20:20.387: pygobject_register_wrapper: assertion 'PyObject_TypeCheck(self, &PyGObject_Type)' failed
Segmentation fault (core dumped)
Expected outcome
An empty interactive graph window shows up, which you can hover your mouse over without causing a segmentation fault.
Additional information
This bug started to happen when I recently updated Matplotlib to the latest version. In earlier versions, things worked as expected. However, I updated several libraries at the same time, so it might be one of them that is the problem.
It only happens when using a GTK4 backend (both Cairo and Agg cause problems). GTK3 works though.
Using faulthandler:
import matplotlib.pyplot as plt
import faulthandler
faulthandler.enable()
plt.plot(1,2)
plt.show()
You get the following output:
/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backends/backend_gtk4.py:160: Warning: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
guiEvent=controller.get_current_event(),
/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backends/backend_gtk4.py:160: Warning: g_object_is_floating: assertion 'G_IS_OBJECT (object)' failed
guiEvent=controller.get_current_event(),
/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backends/backend_gtk4.py:160: Warning: g_object_ref_sink: assertion 'G_IS_OBJECT (object)' failed
guiEvent=controller.get_current_event(),
** (python3:239212): CRITICAL **: 20:31:10.373: pygobject_register_wrapper: assertion 'PyObject_TypeCheck(self, &PyGObject_Type)' failed
Fatal Python error: Segmentation fault
Current thread 0x00007029b9993000 (most recent call first):
File "/usr/lib/python3/dist-packages/gi/overrides/Gio.py", line 42 in run
File "/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backends/_backend_gtk.py", line 206 in start_main_loop
File "/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 3547 in show
File "/home/enprogrammerare/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 614 in show
File "<stdin>", line 1 in <module>
Extension modules: numpy._core._multiarray_umath, numpy.linalg._umath_linalg, PIL._imaging, kiwisolver._cext, gi._gi, cairo._cairo, gi._gi_cairo (total: 7)
Segmentation fault (core dumped)
Operating system
Ubuntu 22.04.2
Matplotlib Version
3.10.0
Matplotlib Backend
GTK4
Python version
3.10.12
Jupyter version
No response
Installation
pip