--- gdkdisplay-x11.c.orig	Wed Mar 16 05:25:09 2005
+++ gdkdisplay-x11.c	Wed May 18 08:47:00 2005
@@ -699,9 +699,11 @@ gdk_display_x11_dispose (GObject *object
 {
   GdkDisplayX11 *display_x11;
   gint i;
-  
   display_x11 = GDK_DISPLAY_X11 (object);
   
+  if(!display_x11->xdisplay)
+    return;
+
   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
     _gdk_screen_close (display_x11->screens[i]);
 
@@ -734,7 +736,8 @@ gdk_display_x11_finalize (GObject *objec
   g_hash_table_destroy (display_x11->atom_from_virtual);
   g_hash_table_destroy (display_x11->atom_to_virtual);
   /* Leader Window */
-  XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
+  if(display_x11->xdisplay)
+    XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
   /* list of filters for client messages */
   g_list_free (display_x11->client_filters);
   /* List of event window extraction functions */
@@ -752,8 +755,9 @@ gdk_display_x11_finalize (GObject *objec
     g_object_unref (tmp->data);
   g_list_free (display_x11->input_windows);
   /* Free all GdkScreens */
-  for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
-    g_object_unref (display_x11->screens[i]);
+  if(display_x11->xdisplay)
+    for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
+      g_object_unref (display_x11->screens[i]);
   g_free (display_x11->screens);
   g_free (display_x11->startup_notification_id);
   
@@ -829,14 +833,16 @@ gdk_x11_display_get_xdisplay (GdkDisplay
 void
 _gdk_windowing_set_default_display (GdkDisplay *display)
 {
-  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
+  GdkDisplayX11 *display_x11;
   const gchar *startup_id;
   
-  if (display)
-    gdk_display = GDK_DISPLAY_XDISPLAY (display);
-  else
+  if (!display) {
     gdk_display = NULL;
+    return;
+  }
 
+  gdk_display = GDK_DISPLAY_XDISPLAY (display);
+  display_x11 = GDK_DISPLAY_X11 (display);
   g_free (display_x11->startup_notification_id);
   display_x11->startup_notification_id = NULL;
   
