Subject: bug#21732: 25.0.50; intermittent failure using windmove when in doc-view buffer

From: Eli Zaretskii <[email-masked]>
Date: Thu, 22 Oct 2015 17:56:43 +0300

> From: Daniel McClanahan <[email-masked]>
> Date: Thu, 22 Oct 2015 02:12:05 -0500
> 
> I've been experiencing this issue at least for months, I don't think I
> remember a time when it wasn't happening (I've only used emacs for a
> year or so). Occasionally, when viewing a file in doc-view-mode, I've
> noticed that using windmove (which I use for all my window movements)
> left, right, up, or down occasionally fails, throwing the error "Wrong
> type argument: wholenump, -<num>", for some number num.
> 
> I've attached gdb and found that this is because "cursor.y" of the
> window being chosen is negative, which I found after attaching a
> breakpoint to "posn-at-point," which was throwing the error, and
> following it down a few calls to "pos_visible_p", and checking the
> value of "w" in there. I don't know what "w->cursor.y" represents (I
> know it's cursor position, but I don't know how that maps to the
> cursor's lisp representation), and although I've delved into xdisp.c
> to see why that would be negative (but only sometimes) in doc-view
> buffers, I haven't been able to see where the cursor position is
> updated, and I've spent a few hours checking it out but am finding it
> difficult to follow a lot of the xdisp.c code.

Thanks for looking so deep into this problem.

First, I believe the function that was signaling an error is
posn-at-x-y, which is called internally by posn-at-point; the latter
AFAICS doesn't make any checks that could cause such an error to be
signaled.  Is that correct?

Also, the coordinates of the cursor are not related to what these
functions do or the data they examine, except accidentally, if the
position passed to posn-at-point was that of point.  (To answer your
question, w->cursor.y is the vertical window-relative coordinate in
pixels of the cursor position in window w.  If that value is -1, it
means Emacs didn't yet compute the cursor position in that window,
which could happen if the problem happens in the middle of a redisplay
cycle.  Martin described another situation where it might be
negative.)

So to get the investigation of this bug forward, could you post here
the C-level backtrace you get in GDB when this error is signaled?
Please accompany it with the output of the "xbacktrace" GDB command,
which should show the corresponding Lisp backtrace.  (This command is
defined in the file src/.gdbinit in the Emacs source tree, so you will
have to source that file before issuing the command.)

Finally, please post the information about your system and the Emacs
configuration produced by "M-x report-Emacs-bug RET".

> Steps to reproduce: kind of hard, since it's very intermittent.

It might help to find out with which arguments was posn-at-point (or
was it posn-at-x-y?) called, and then try reproducing the problem by
manually calling that function with the same arguments in the same
buffer.  If that works, you will have a reproducible recipe.