Reopen window throws Gtk-CRITICAL **: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed

拜拜、爱过 提交于 2021-02-05 08:44:09

问题


I have simple python3 + gtk3 code, which connects to dbus and listen for all events. When user click on icon in tray, he must see window with all showed earlier events. Code(I don't know where is problem and code size > 100 lines): https://github.com/rakshazi/notify-feed/blob/master/main.py

How to reproduce:

  1. Run python main.py L117
  2. Click on app icon in tray - will be opened window, it can be empty or with some items if any notifications was shown after run. L83
  3. Close window. L93
  4. Retry step #2, you will see empty window (without any element in all cases, yes, it is bug, but doesn't matter for this question)
  5. Click on window body and app will be crashed:

    (gui.py:4882): Gtk-CRITICAL **: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed [1] 4882 segmentation fault (core dumped) python gui.py

On first windowOpen event and on second windowOpen event self.window object is <__main__.Window object at 0x7f98b1dcd7e0 (__main__+Window at 0x1502260)>

gdb result:

(main.py:17310): Gtk-CRITICAL **: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007fffea5cd0b8 in gtk_widget_translate_coordinates () from /usr/lib/libgtk-3.so.0

Please, explain to me how to debug and fix this problem.

PS: I'm new to Python, that's why this problem may be stupid.


回答1:


Lesson 1: Never assume bugs are unrelated

Lesson 2: GTK events are confusing.

The reason you get this error is because the window is actually deleted in you close it in step 3, therefor all the widgets in the window become orphans (they have no parent) and are therefor cleaned. The second time you open the window in step 4 the window only contains references to deleted widgets causing your segmentation fault.

The solution is surprisingly simple just add return True to closeWindow this will let GTK know the event has been handle and that it should not perform the default action of closing the window (that you already hide).



来源:https://stackoverflow.com/questions/40736476/reopen-window-throws-gtk-critical-gtk-widget-get-window-assertion-gtk-is-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!