From 7f4d96f960dcba6778d2c2dde2d653c9446115e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sat, 8 Feb 2020 17:10:48 +0100 Subject: ui/gtk: Fix gd_refresh_rate_millihz() when widget window is not realized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gtk_widget_get_window() returns NULL if the widget's window is not realized, and QEMU crashes. Example under gtk 3.22.30 (mate 1.20.1): qemu-system-x86_64: Gdk: gdk_window_get_origin: assertion 'GDK_IS_WINDOW (window)' failed (gdb) bt #0 0x00007ffff496cf70 in gdk_window_get_origin () from /usr/lib64/libgdk-3.so.0 #1 0x00007ffff49582a0 in gdk_display_get_monitor_at_window () from /usr/lib64/libgdk-3.so.0 #2 0x0000555555bb73e2 in gd_refresh_rate_millihz (window=0x5555579d6280) at ui/gtk.c:1973 #3 gd_vc_gfx_init (view_menu=0x5555579f0590, group=0x0, idx=0, con=, vc=0x5555579d4a90, s=0x5555579d49f0) at ui/gtk.c:2048 #4 gd_create_menu_view (s=0x5555579d49f0) at ui/gtk.c:2149 #5 gd_create_menus (s=0x5555579d49f0) at ui/gtk.c:2188 #6 gtk_display_init (ds=, opts=0x55555661ed80 ) at ui/gtk.c:2256 #7 0x000055555583d5a0 in main (argc=, argv=, envp=) at vl.c:4358 Fixes: c4c00922cc and 28b58f19d2 (display/gtk: get proper refreshrate) Reported-by: Jan Kiszka Signed-off-by: Philippe Mathieu-Daudé Tested-by: Jan Kiszka Message-id: 20200208161048.11311-3-f4bug@amsat.org Signed-off-by: Gerd Hoffmann --- ui/gtk.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/gtk.c b/ui/gtk.c index c59297ff4d..850c49bee0 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1968,14 +1968,16 @@ static GtkWidget *gd_create_menu_machine(GtkDisplayState *s) static int gd_refresh_rate_millihz(GtkWidget *window) { #ifdef GDK_VERSION_3_22 - GdkDisplay *dpy = gtk_widget_get_display(window); GdkWindow *win = gtk_widget_get_window(window); - GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); - return gdk_monitor_get_refresh_rate(monitor); -#else - return 0; + if (win) { + GdkDisplay *dpy = gtk_widget_get_display(window); + GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); + + return gdk_monitor_get_refresh_rate(monitor); + } #endif + return 0; } static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, -- cgit v1.2.3