[Spice-devel] gtk_widget_get_window may return NULL

Marc-André Lureau mlureau at redhat.com
Tue Sep 24 05:47:31 PDT 2013



----- Original Message -----
> I try to cross compile virt-viewer to win32 using Debian Jessie. So far it
> works,
> but only if I apply the following patch to spice-widget.c:
> 
> Index: new/gtk/spice-widget.c
> ===================================================================
> --- new.orig/gtk/spice-widget.c	2013-06-26 15:55:08.000000000 +0200
> +++ new/gtk/spice-widget.c	2013-09-24 12:00:17.889780000 +0200
> @@ -1286,7 +1286,12 @@
>  static void update_display(SpiceDisplay *display)
>  {
>  #ifdef WIN32
> -    win32_window = display ?
> GDK_WINDOW_HWND(gtk_widget_get_window(GTK_WIDGET(display))) : NULL;
> +    if (!display)
> +        return;
> +
> +    GdkWindow *win = gtk_widget_get_window(GTK_WIDGET(display));
> +
> +    win32_window = win ? GDK_WINDOW_HWND(win) : NULL;
>  #endif
>  }
> 
> Seems that update_display() is called early on startup when the window is not
> realized.

Do you have a backtrace?

It should only be called in enter or focus events, which I assume shouldn't happen when the widget is not realized.

> So this results is a call to GDK_WINDOW_HWND(NULL), which simply crash
> remote-viewer.exe

Ok that macro isn't safe. Why do you check (!display), this would really be a programming bug, more than runtime bug. 

I think we should also keep warning when this happen, since it may result in buggy keyboard behaviour later on. ie, doing this:

{
  GdkWindow *win = gtk_widget_get_window(GTK_WIDGET(display));
  g_return_if_fail(win != NULL);
  win32_window = GDK_WINDOW_HWND(win); 
}

> I have no idea why this only happens with the binaries I compiled myself.

What version of gtk?

(I haven't tried gtk3 on windows for a long time)


More information about the Spice-devel mailing list