$NetBSD: patch-ai,v 1.2 2000/02/03 16:01:15 abs Exp $

--- linuxdoom-1.10/i_video.c.orig	Mon Dec 22 20:39:01 1997
+++ linuxdoom-1.10/i_video.c	Thu Feb  3 02:48:08 2000
@@ -36,7 +36,7 @@
 #include <X11/extensions/XShm.h>
 // Had to dig up XShm.c for this one.
 // It is in the libXext, but not in the XFree86 headers.
-#ifdef LINUX
+#if defined(LINUX) || defined (__NetBSD__)
 int XShmGetEventBase( Display* dpy ); // problems with g++?
 #endif
 
@@ -46,13 +46,14 @@
 #include <sys/socket.h>
 
 #include <netinet/in.h>
-#include <errnos.h>
+#include <errno.h>
 #include <signal.h>
 
 #include "doomstat.h"
 #include "i_system.h"
 #include "v_video.h"
 #include "m_argv.h"
+#include "m_swap.h"	/* For BYTE_ORDER == BIG_ENDIAN */
 #include "d_main.h"
 
 #include "doomdef.h"
@@ -164,15 +165,20 @@
 void I_ShutdownGraphics(void)
 {
   // Detach from X server
-  if (!XShmDetach(X_display, &X_shminfo))
+  if (X_shminfo.shmid)
+  {
+      if (!XShmDetach(X_display, &X_shminfo))
 	    I_Error("XShmDetach() failed in I_ShutdownGraphics()");
 
-  // Release shared memory.
-  shmdt(X_shminfo.shmaddr);
-  shmctl(X_shminfo.shmid, IPC_RMID, 0);
+      // Release shared memory.
+      shmdt(X_shminfo.shmaddr);
+      shmctl(X_shminfo.shmid, IPC_RMID, 0);
+      X_shminfo.shmid = 0;
+  }
 
   // Paranoia.
-  image->data = NULL;
+  if (image)
+      image->data = NULL;
 }
 
 
