🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #87668

'Bad Window' X error: found it!

#87668
From: garyo
Date: Thu, 08 Sep 1994 22:38
287 lines
9880 bytes
In GNU Emacs 19.25.95.4 (sparc-sun-solaris2.3, X toolkit) of Wed Aug 31 1994 on prometheus

I've been trying to track down this error I get once every few days
while deleting a frame:

"X protocol error: BadWindow (invalid Window parameter) on protocol request 40"

I'm running the OpenWindows server that comes with Solaris 2.3, with
twm as a window mgr.

It's hard to reproduce, but I finally got it under gdb.  I don't know
for sure the cause, but I know just where it is.  It seems to be a
race condition: while translating coordinates, the window in question
is deleted, and so the XTranslateCoordinates [this is request 40, BTW]
fails with the above error.

Here's the code in question:

	    while (1)
	      {
		XTranslateCoordinates (x_current_display,

				       /* From-window, to-window.  */
				       root, win,

				       /* From-position, to-position.  */
				       root_x, root_y, &win_x, &win_y,

				       /* Child of win.  */
				       &child);

		if (child == None)
		  break;

		win = child;
		parent_x = win_x;
		parent_y = win_y;
	      }

I don't know exactly how this can happen; if there's a pending request
for deletion, it should be flushed and honored before the first
XTranslateCoordinates request, so it should always return a valid
window.  No requests can get in between successive
XTranslateCoordinates requests in the while loop, so the child window
should *stay* valid each time through.

Note that XTranslateCoordinates *can* return 0, but the doc says it
only happens if the src and dest are on different screens, so that's
not supposed to happen.  Besides I don't think that's what's happening
since the other variables seem to be fine.

About all I can think of is to catch the error with x_error_catcher
and ignore it (assume the mouse is not in emacs' window).  Don't know
if this is a Solaris/OpenWindows thing.

Here's the gdb info I've collected [my notes are in square braces]:

Breakpoint 2, x_error_quitter (display=0x1aa800, error=0xefffe870)
    at xterm.c:4986
4986      XGetErrorText (display, error->error_code, buf, sizeof (buf));
(gdb) where
#0  x_error_quitter (display=0x1aa800, error=0xefffe870) at xterm.c:4986
#1  0xef65b248 in char_ins_del_vector ()
#2  0xef64f090 in char_ins_del_vector ()
#3  0xef6521b4 in char_ins_del_vector ()
#4  0x49c24 in XTmouse_position (f=0xefffeae4, bar_window=0xefffeae0, 
    part=0xefffeadc, x=0xefffead8, y=0xefffead4, time=0xefffead0)
    at xterm.c:2537
#5  0x363d4 in Fmouse_position () at frame.c:997
#6  0x9c7c4 in Ffuncall (nargs=135109040, args=0xefffebec) at eval.c:2053
#7  0xae8f4 in Fbyte_code (bytestr=52628304, vector=69312768, maxdepth=0)
    at bytecode.c:422
#8  0x9cdec in funcall_lambda (fun=102934496, nargs=0, arg_vector=0xefffee0c)
    at eval.c:2231
#9  0x9c924 in Ffuncall (nargs=102934496, args=0xefffee08) at eval.c:2106
#10 0xae8f4 in Fbyte_code (bytestr=51299392, vector=68076688, maxdepth=0)
    at bytecode.c:422
#11 0x9cdec in funcall_lambda (fun=101630996, nargs=1, arg_vector=0xeffff024)
#12 0x9c924 in Ffuncall (nargs=101630996, args=0xeffff020) at eval.c:2106
#13 0x9c378 in call1 (fn=18226920, arg1=18239248) at eval.c:1850
#14 0x5da78 in safe_run_hooks (hook=18239228) at keyboard.c:1287
#15 0x5d920 in command_loop_1 () at keyboard.c:1238
#16 0x9add4 in internal_condition_case (bfun=0x5cfac <command_loop_1>, 
---Type <return> to continue, or q <return> to quit---
    handlers=18189616, hfun=0x5ca98 <cmd_error>) at eval.c:1096
#17 0x5ce2c in command_loop_2 () at keyboard.c:879
#18 0x9a950 in internal_catch (tag=18189596, func=0x5ce08 <command_loop_2>, 
    arg=18189316) at eval.c:886
#19 0x5cdd8 in command_loop () at keyboard.c:859
#20 0x5c918 in recursive_edit_1 () at keyboard.c:694
#21 0x5ca30 in Frecursive_edit () at keyboard.c:736
#22 0x5bfa4 in main (argc=3, argv=0xeffff5ec, envp=0xeffff5fc) at emacs.c:762
(gdb) up
#1  0xef65b248 in char_ins_del_vector ()
(gdb) up
#2  0xef64f090 in char_ins_del_vector ()
(gdb) up
#3  0xef6521b4 in char_ins_del_vector ()
(gdb) up
#4  0x49c24 in XTmouse_position (f=0xefffeae4, bar_window=0xefffeae0, 
    part=0xefffeadc, x=0xefffead8, y=0xefffead4, time=0xefffead0)
    at xterm.c:2537
2537                    XTranslateCoordinates (x_current_display,
(gdb) p f
$1 = (struct frame **) 0xefffeae4
(gdb) p *f
$2 = (struct frame *) 0x2a5400
(gdb) p **f
$3 = {
  size = 40, 
  next = 0x390360, 
  current_glyphs = 0x2b98c0, 
  desired_glyphs = 0x2b9740, 
  insert_line_cost = 0x3cfc00, 
  delete_line_cost = 0x652500, 
  insert_n_lines_cost = 0x3cff00, 
  delete_n_lines_cost = 0x3cf100, 
  temp_glyphs = 0x2b97c0, 
  cursor_x = 0, 
  cursor_y = 5, 
  phys_cursor_x = 0, 
  phys_cursor_y = 5, 
  phys_cursor_glyph = 813, 
  height = 53, 
  width = 80, 
  new_height = 0, 
  new_width = 0, 
  name = 53083868, 
  focus_frame = 18189316, 
  root_window = 343490816, 
  selected_window = 343490816, 
---Type <return> to continue, or q <return> to quit---
  param_alist = 87465260, 
  scroll_bars = 74147456, 
  condemned_scroll_bars = 18189316, 
  menu_bar_items = 69477760, 
  face_alist = 87463132, 
  output_method = output_x_window, 
  display = {
    x = 0x2a5500, 
    nothing = 2774272
  }, 
  menu_bar_lines = 0, 
  external_menu_bar = 1, 
  display_preempted = 0 '\000', 
  visible = 1 '\001', 
  iconified = 0 '\000', 
  async_visible = 1 '\001', 
  async_iconified = 0 '\000', 
  garbaged = 0 '\000', 
  has_minibuffer = 1 '\001', 
  wants_modeline = 1 '\001', 
  can_have_scroll_bars = 1 '\001', 
  has_vertical_scroll_bars = 1 '\001', 
---Type <return> to continue, or q <return> to quit---
  auto_raise = 0 '\000', 
  auto_lower = 0 '\000', 
  no_split = 0 '\000', 
  explicit_name = 1 '\001', 
  message_buf = 0x399380 "Wrote /net/caffeine/home1/garyo/Mail/sent", 
  scroll_bottom_vpos = -1, 
  menu_bar_vector = 18189316, 
  menu_bar_items_used = 0
}
---Type <return> to continue, or q <return> to quit---
  minibuffer_window = 338318848, 
  param_alist = 87465260, 
  scroll_bars = 74147456, 
  condemned_scroll_bars = 18189316, 
  menu_bar_items = 69477760, 
  face_alist = 87463132, 
  output_method = output_x_window, 
  display = {
    x = 0x2a5500, 
    nothing = 2774272
  }, 
  menu_bar_lines = 0, 
  external_menu_bar = 1, 
  display_preempted = 0 '\000', 
  visible = 1 '\001', 
  iconified = 0 '\000', 
  async_visible = 1 '\001', 
  async_iconified = 0 '\000', 
  garbaged = 0 '\000', 
  has_minibuffer = 1 '\001', 
  wants_modeline = 1 '\001', 
  can_have_scroll_bars = 1 '\001', 
  has_vertical_scroll_bars = 1 '\001', 
---Type <return> to continue, or q <return> to quit---
  auto_raise = 0 '\000', 
  auto_lower = 0 '\000', 
  no_split = 0 '\000', 
  explicit_name = 1 '\001', 
  message_buf = 0x399380 "Wrote /net/caffeine/home1/garyo/Mail/sent", 
  scroll_bottom_vpos = -1, 
  menu_bar_vector = 18189316, 
  menu_bar_items_used = 0
}
(gdb) 
(gdb) p x_current_display
$4 = (Display *) 0x1aa800
(gdb) p root
$5 = 41
(gdb) p win
$6 = 29361191
(gdb) 
[note: there's no such window as 'win' on my display anymore]
(gdb) p root_x
$7 = 499
(gdb) p root_y
$8 = 468
(gdb) p win_x
$9 = 499
(gdb) p win_y
$10 = 468
(gdb) (gdb) p parent_x
$11 = 499
(gdb) p parent_y
$12 = 468
(gdb) p child
$13 = 29361191
(gdb) 
[no such win as this either]
(gdb) p x_mouse_grabbed
$14 = 0
(gdb) p last_mouse_frame
$15 = (struct frame *) 0x2a5400
(gdb) 
(gdb) p *last_mouse_frame
$16 = {
  size = 40, 
  next = 0x390360, 
  current_glyphs = 0x2b98c0, 
  desired_glyphs = 0x2b9740, 
  insert_line_cost = 0x3cfc00, 
  delete_line_cost = 0x652500, 
  insert_n_lines_cost = 0x3cff00, 
  delete_n_lines_cost = 0x3cf100, 
  temp_glyphs = 0x2b97c0, 
  cursor_x = 0, 
  cursor_y = 5, 
  phys_cursor_x = 0, 
  phys_cursor_y = 5, 
  phys_cursor_glyph = 813, 
  height = 53, 
  width = 80, 
  new_height = 0, 
  new_width = 0, 
  name = 53083868, 
  focus_frame = 18189316, 
  root_window = 343490816, 
  selected_window = 343490816, 
---Type <return> to continue, or q <return> to quit---
  minibuffer_window = 338318848, 
  param_alist = 87465260, 
  scroll_bars = 74147456, 
  condemned_scroll_bars = 18189316, 
  menu_bar_items = 69477760, 
  face_alist = 87463132, 
  output_method = output_x_window, 
  display = {
    x = 0x2a5500, 
    nothing = 2774272
  }, 
  menu_bar_lines = 0, 
  external_menu_bar = 1, 
  display_preempted = 0 '\000', 
  visible = 1 '\001', 
  iconified = 0 '\000', 
  async_visible = 1 '\001', 
  async_iconified = 0 '\000', 
  garbaged = 0 '\000', 
  has_minibuffer = 1 '\001', 
  wants_modeline = 1 '\001', 
  can_have_scroll_bars = 1 '\001', 
  has_vertical_scroll_bars = 1 '\001', 
---Type <return> to continue, or q <return> to quit---
  auto_raise = 0 '\000', 
  auto_lower = 0 '\000', 
  no_split = 0 '\000', 
  explicit_name = 1 '\001', 
  message_buf = 0x399380 "Wrote /net/caffeine/home1/garyo/Mail/sent", 
  scroll_bottom_vpos = -1, 
  menu_bar_vector = 18189316, 
  menu_bar_items_used = 0
}
(gdb) 
Technical Details
Message-ID: <9409082234.AA02605@prometheus>
Path: arc1-ca.pugleaf.net!nntp.gmd.de!xlink.net!slsv6bt!slbh01.bln.sel.alcatel.de!rcvie!Austria.EU.net!EU.net!howland.reston.ans.net!math.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!avs.com!garyo

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,8b10e998dc0a25d3,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-09-09 00:50:59 PST
Path: arc1-ca.pugleaf.net!nntp.gmd.de!xlink.net!slsv6bt!slbh01.bln.sel.alcatel.de!rcvie!Austria.EU.net!EU.net!howland.reston.ans.net!math.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!avs.com!garyo
From: garyo@avs.com
Newsgroups: gnu.emacs.bug
Subject: 'Bad Window' X error: found it!
Date: 8 Sep 1994 18:38:52 -0400
Organization: GNUs Not Usenet
Lines: 287
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9409082234.AA02605@prometheus>