Subject: Re: bug#71274: 30.0.50; assertion failed: w->window_end_valid, in find_first_unchanged_at_end_row

From: Eli Zaretskii <[email-masked]>
Date: Thu, 30 May 2024 14:38:29 +0300

> From: Daniel Clemente <[email-masked]>
> Date: Thu, 30 May 2024 09:51:20 +0000
> 
> I have --enable-checking=yes,glyphs enabled, and am using emacsclient
> without X support but inside a urxvt terminal in X. Built with no
> extra patches. Running in gdb.
> 
> I was editing Python code when this error happened. Last things I did were:
> M-space to remove extra spaces, and by mistake I hit S-space which
> enabled scim (input method chooser, a small widget appearing on top
> and stealing window-manager focus), then I disabled it again.
> This information may be bogus since these operations work fine when I
> retest them.
> I wasn't doing anything weird like stress-testing it, resizing
> windows, changing fonts/resolution, …
> 
> I don't know how to reproduce this yet. Feel free to close if it
> doesn't clearly show a possible bug.

Not only does it not show a possible bug, it actually shows an
impossible condition.  I feel like I must be missing something here,
because this simply cannot happen, if my reading of the code is
correct.  See below.

> (gdb) bt
> #0  terminate_due_to_signal (sig=6, backtrace_limit=2147483647) at emacs.c:443
> #1  0x00005555557350bb in die (msg=0x5555558527c0 "w->window_end_valid",
>     file=0x555555850b08 "xdisp.c", line=21783) at alloc.c:8082
> #2  0x00005555555dcd5f in find_first_unchanged_at_end_row (w=0x5555622c4f68,
>     delta=0x7fffffff7b18, delta_bytes=0x7fffffff7b10) at xdisp.c:21783

This points to the following assertion:

  static struct glyph_row *
  find_first_unchanged_at_end_row (struct window *w,
				   ptrdiff_t *delta, ptrdiff_t *delta_bytes)
  {
    struct glyph_row *row;
    struct glyph_row *row_found = NULL;

    *delta = *delta_bytes = 0;

    /* Display must not have been paused, otherwise the current matrix
       is not up to date.  */
    eassert (w->window_end_valid); <<<<<<<<<<<<<<<<<<<<<<

However, find_first_unchanged_at_end_row is called from try_window_id:

> #3  0x00005555555de527 in try_window_id (w=0x5555622c4f68) at xdisp.c:22347

And that function already checked that w->window_end_valid is
non-zero, several dozens of lines before that:

    /* Verify that display wasn't paused.  */
    if (!w->window_end_valid)
      GIVE_UP (8);

GIVE_UP returns from the function.  So how come w->window_end_valid
became zero between that test and the assertion, Emacs being a
single-threaded program??  What am I missing here?  The only possible
explanation I could think of is some compiler bug that causes it to
emit incorrect code, or maybe some hardware problem with memory.  Both
possibilities are almost unthinkable.

Any ideas, even crazy ones, are welcome.