Index: src/window.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/window.c,v
retrieving revision 1.41.2.58
diff -u -r1.41.2.58 window.c
--- src/window.c 2000/08/18 17:16:06 1.41.2.58
+++ src/window.c 2000/08/21 17:29:22
@@ -5200,12 +5200,18 @@
       record_unwind_protect (free_window_configuration, old_window_config);
 
       mark_windows_in_use (f, 1);
-
+#if 0
       /* Force subwindows to be reinstantiated. They are all going
-         anyway and if we don't do this GC may not happen between now
-         and the next time we check their integrity. */
-      reset_frame_subwindow_instance_cache (f);
+	 anyway and if we don't do this GC may not happen between now
+	 and the next time we check their integrity.  
 
+	 #### This is wrong because an instance is only put in the
+	 frame cache when it is instantiated, so if we do this there
+	 is a chance that stuff will never get put back in the frame
+	 task. However, there maybe other reasons for doing something
+	 similar.*/
+      reset_frame_subwindow_instance_cache (f);
+#endif
 #if 0
       /* JV: This is bogus,
 	 First of all, the units are inconsistent. The frame sizes are measured
@@ -5351,7 +5357,7 @@
 	  /* When we restore a window's configuration, the identity of
 	     the window hasn't actually changed - so there is no
 	     reason why we shouldn't preserve the instance cache for
-	     it - unless it was origincally deleted. This will often
+	     it - unless it was originally deleted. This will often
 	     buy us something as we will not have to re-instantiate
 	     all the instances. This is because this is an instance
 	     cache - not a display cache. Preserving the display cache
Index: src/glyphs.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/glyphs.c,v
retrieving revision 1.23.2.80
diff -u -r1.23.2.80 glyphs.c
--- src/glyphs.c 2000/08/18 17:16:03 1.23.2.80
+++ src/glyphs.c 2000/08/21 17:29:34
@@ -4299,13 +4299,16 @@
     {
       struct frame* f = XFRAME (XIMAGE_INSTANCE_FRAME (value));
       unmap_subwindow (value);
-      /* In case GC doesn't catch up fast enough, remove from the frame
-	 cache also. Otherwise code that checks the sanity of the instance
-	 will fail. */
-      XWEAK_LIST_LIST (FRAME_SUBWINDOW_CACHE (f))
-	= delq_no_quit (value, XWEAK_LIST_LIST (FRAME_SUBWINDOW_CACHE (f)));
       if (finalize)
-	finalize_image_instance (XIMAGE_INSTANCE (value), 0);
+	{
+	  /* In case GC doesn't catch up fast enough, remove from the frame
+	     cache also. Otherwise code that checks the sanity of the instance
+	     will fail. */
+	  XWEAK_LIST_LIST (FRAME_SUBWINDOW_CACHE (f))
+	    = delq_no_quit (value, 
+			    XWEAK_LIST_LIST (FRAME_SUBWINDOW_CACHE (f)));
+	  finalize_image_instance (XIMAGE_INSTANCE (value), 0);
+	}
     }
   return 0;
 }
@@ -4342,9 +4345,8 @@
       /* Make sure that the subwindow is unmapped so that window
 	 deletion will not try and do it again. */
       unmap_subwindow (value);
-      XWEAK_LIST_LIST (FRAME_SUBWINDOW_CACHE (f))
-	= delq_no_quit (value, XWEAK_LIST_LIST (FRAME_SUBWINDOW_CACHE (f)));
     }
+  XWEAK_LIST_LIST (FRAME_SUBWINDOW_CACHE (f)) = Qnil;
 }
 
 /*****************************************************************************
@@ -4591,7 +4593,7 @@
     return;
 
 #ifdef DEBUG_WIDGETS
-  stderr_out ("unmapping subwindow %d\n", IMAGE_INSTANCE_SUBWINDOW_ID (ii));
+  stderr_out ("unmapping subwindow %p\n", IMAGE_INSTANCE_SUBWINDOW_ID (ii));
 #endif
   f = XFRAME (IMAGE_INSTANCE_FRAME (ii));
 
@@ -4620,12 +4622,11 @@
     return;
 
 #ifdef DEBUG_WIDGETS
-  stderr_out ("mapping subwindow %d, %dx%d@%d+%d\n",
+  stderr_out ("mapping subwindow %p, %dx%d@%d+%d\n",
 	      IMAGE_INSTANCE_SUBWINDOW_ID (ii),
 	      dga->width, dga->height, x, y);
 #endif
   f = XFRAME (IMAGE_INSTANCE_FRAME (ii));
-  IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (ii) = 1;
   IMAGE_INSTANCE_DISPLAY_X (ii) = x;
   IMAGE_INSTANCE_DISPLAY_Y (ii) = y;
   IMAGE_INSTANCE_DISPLAY_WIDTH (ii) = dga->width;
@@ -4633,6 +4634,7 @@
 
   MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
 		 map_subwindow, (ii, x, y, dga));
+  IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (ii) = 1;
 }
 
 static int
Index: src/glyphs-x.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/glyphs-x.c,v
retrieving revision 1.49.2.77
diff -u -r1.49.2.77 glyphs-x.c
--- src/glyphs-x.c 2000/08/18 17:16:02 1.49.2.77
+++ src/glyphs-x.c 2000/08/21 17:29:40
@@ -2147,8 +2147,9 @@
 			 x, y, dga->width, dga->height);
       XMoveWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
 		   subwindow, -dga->xoffset, -dga->yoffset);
-      XMapWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
-		  IMAGE_INSTANCE_X_CLIPWINDOW (p));
+      if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
+	XMapWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
+		    IMAGE_INSTANCE_X_CLIPWINDOW (p));
     }
   else				/* must be a widget */
     {
@@ -2158,7 +2159,8 @@
 			 dga->width, dga->height, 0);
       XtMoveWidget (IMAGE_INSTANCE_X_WIDGET_ID (p),
 		    -dga->xoffset, -dga->yoffset);
-      XtMapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
+      if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
+	XtMapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
     }
 }
 
Index: src/glyphs-msw.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/glyphs-msw.c,v
retrieving revision 1.21.2.64
diff -u -r1.21.2.64 glyphs-msw.c
--- src/glyphs-msw.c 2000/08/18 17:16:01 1.21.2.64
+++ src/glyphs-msw.c 2000/08/21 17:29:47
@@ -2236,32 +2236,36 @@
 		SWP_NOZORDER | SWP_NOSIZE
 		| SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
   /* ... now map it - we are not allowed to move it at the same time. */
+  if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
+    {
 #ifdef DEFER_WINDOW_POS
-  new_hdwp = DeferWindowPos (hdwp, IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p),
-			     NULL,
-			     0, 0, 0, 0,
-			     SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE
-			     | SWP_SHOWWINDOW
-			     /* | SWP_NOCOPYBITS */
-			     /* Setting this flag causes the call to
-				DeferWindowPos to fail with
-				"Invalid parameter".  I don't understand
-				why we bother to try and set this
-				anyway. -- ben */
-			     /* | SWP_NOSENDCHANGING */
-			     | SWP_NOACTIVATE);
-  if (!new_hdwp)
-    mswindows_output_last_error ("mapping");
-  else
-    hdwp = new_hdwp;
-  FRAME_MSWINDOWS_DATA (f)->hdwp = hdwp;
+      new_hdwp = DeferWindowPos 
+	(hdwp, 
+	 IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p),
+	 NULL, 0, 0, 0, 0,
+	 SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE
+	 | SWP_SHOWWINDOW
+	 /* | SWP_NOCOPYBITS */
+	 /* Setting this flag causes the call to
+	    DeferWindowPos to fail with
+	    "Invalid parameter".  I don't understand
+	    why we bother to try and set this
+	    anyway. -- ben */
+	 /* | SWP_NOSENDCHANGING */
+	 | SWP_NOACTIVATE);
+      if (!new_hdwp)
+	mswindows_output_last_error ("mapping");
+      else
+	hdwp = new_hdwp;
+      FRAME_MSWINDOWS_DATA (f)->hdwp = hdwp;
 #else
-  SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p),
-		NULL,
-		0, 0, 0, 0,
-		SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE
-		| SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOACTIVATE);
+      SetWindowPos (IMAGE_INSTANCE_MSWINDOWS_CLIPWINDOW (p),
+		    NULL,
+		    0, 0, 0, 0,
+		    SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE
+		    | SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOACTIVATE);
 #endif
+    }
 }
 
 /* resize the subwindow instance */
