$NetBSD: patch-zy,v 1.1 2007/07/16 10:12:46 xtraeme Exp $

--- src/xitk/actions.c.orig	2007-04-07 00:52:54.000000000 +0000
+++ src/xitk/actions.c	2007-06-07 00:15:04.000000000 +0000
@@ -638,58 +638,77 @@
 
   if(video_window_is_visible())
     video_window_set_visibility(0);
+
+  config_update_num("gui.amp_level", gGui->mixer.amp_level);
+  config_save();
   
+  /* we are going to dispose this stream, so make sure slider_loop 
+   * won't use it anymore (otherwise -> segfault on exit).
+   */
+  gGui->running = 0;
+
+  if(gGui->visual_anim.event_queue) {
+    xine_event_dispose_queue(gGui->visual_anim.event_queue);
+    gGui->visual_anim.event_queue = 0;
+  }
+  if(gGui->visual_anim.stream) {
+    xine_dispose(gGui->visual_anim.stream);
+    gGui->visual_anim.stream = 0;
+  }
+
   tvout_deinit(gGui->tvout);
-  video_window_exit();
 
-#ifdef HAVE_XF86VIDMODE
-  /* just in case a different modeline than the original one is running,
-   * toggle back to window mode which automatically causes a switch back to
-   * the original modeline
-   */
-  if(gGui->XF86VidMode_fullscreen)
-    video_window_set_fullscreen_mode(WINDOWED_MODE);
-  //     gui_set_fullscreen_mode(NULL,NULL);
-#endif
-   
+  if(gGui->event_queue) {
+    xine_event_dispose_queue(gGui->event_queue);
+    gGui->event_queue = 0;
+  }
+
   osd_deinit();
 
-  config_update_num("gui.amp_level", gGui->mixer.amp_level);
-  config_save();
-  
+  if(gGui->ao_none) {
+    xine_close_audio_driver(gGui->xine, gGui->ao_none);
+    gGui->ao_none = 0;
+  }
+  if(gGui->vo_none) {
+    xine_close_video_driver(gGui->xine, gGui->vo_none);
+    gGui->vo_none = 0;
+  }
+
   /* Restore old audio volume */
   if(gGui->ao_port && (gGui->mixer.method == SOUND_CARD_MIXER))
     xine_set_param(gGui->stream, XINE_PARAM_AUDIO_VOLUME, gGui->mixer.original_level);
-  
-  xine_close(gGui->stream);
-  xine_close(gGui->visual_anim.stream);
 
-  xine_event_dispose_queue(gGui->event_queue);
-  xine_event_dispose_queue(gGui->visual_anim.event_queue);
-
-  /* we are going to dispose this stream, so make sure slider_loop 
-   * won't use it anymore (otherwise -> segfault on exit).
-   */
-  gGui->running = 0;
+  if(gGui->stream) {
+    xine_dispose(gGui->stream);
+    gGui->stream = 0;
+  }
 
   if(gGui->visual_anim.post_output_element.post)
     xine_post_dispose(gGui->xine, gGui->visual_anim.post_output_element.post);
 
-  xine_dispose(gGui->stream);
-  /* xine_dispose(gGui->visual_anim.stream); */
-
-  if(gGui->vo_port)
+  if(gGui->vo_port) {
     xine_close_video_driver(gGui->xine, gGui->vo_port);
-  if(gGui->vo_none)
-    xine_close_video_driver(gGui->xine, gGui->vo_none);
-
-  if(gGui->ao_port)
+    gGui->vo_port = 0;
+  }
+  if(gGui->ao_port) {
     xine_close_audio_driver(gGui->xine, gGui->ao_port);
-  if(gGui->ao_none)
-    xine_close_audio_driver(gGui->xine, gGui->ao_none);
+    gGui->ao_port = 0;
+  }
 
   xine_exit(gGui->xine); 
+  
+  video_window_exit();
 
+#ifdef HAVE_XF86VIDMODE
+  /* just in case a different modeline than the original one is running,
+   * toggle back to window mode which automatically causes a switch back to
+   * the original modeline
+   */
+  if(gGui->XF86VidMode_fullscreen)
+    video_window_set_fullscreen_mode(WINDOWED_MODE);
+  //     gui_set_fullscreen_mode(NULL,NULL);
+#endif
+   
 #ifdef HAVE_LIRC
   if(gGui->lirc_enable)
     lirc_stop();
