Skip to content

Fix terminal window issue related scrollback (fix: #16024)#16211

Closed
h-east wants to merge 1 commit intovim:masterfrom
h-east:fix-termwin-issue
Closed

Fix terminal window issue related scrollback (fix: #16024)#16211
h-east wants to merge 1 commit intovim:masterfrom
h-east:fix-termwin-issue

Conversation

@h-east
Copy link
Copy Markdown
Member

@h-east h-east commented Dec 13, 2024

Fix: #16024

When switching the current window with mouse operations, update_topline() is not called, resulting in multiple occurrences of E340 and E315.

@h-east
Copy link
Copy Markdown
Member Author

h-east commented Dec 14, 2024

Hmm, Is Test_termwinscroll_topline() flaky?

@chrisbra
Copy link
Copy Markdown
Member

I see it hangs sometimes:

#0  0x00007f0c3011cddd in __GI___writev (iovcnt=3, iov=0x7fff6934b300, fd=3) at ../sysdeps/unix/sysv/linux/writev.c:26
#1  __GI___writev (fd=3, iov=0x7fff6934b300, iovcnt=3) at ../sysdeps/unix/sysv/linux/writev.c:24
#2  0x00007f0c2fa7a010 in ?? () from /lib/x86_64-linux-gnu/libxcb.so.1
#3  0x00007f0c2fa7a409 in xcb_writev () from /lib/x86_64-linux-gnu/libxcb.so.1
#4  0x00007f0c3040ca25 in _XSend () from /lib/x86_64-linux-gnu/libX11.so.6
#5  0x00007f0c3040cb49 in _XEventsQueued () from /lib/x86_64-linux-gnu/libX11.so.6
#6  0x00007f0c303fde17 in XPending () from /lib/x86_64-linux-gnu/libX11.so.6
#7  0x00007f0c30b919d5 in ?? () from /lib/x86_64-linux-gnu/libgdk-3.so.0
#8  0x00007f0c305d53c4 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#9  0x00007f0c305d579e in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#10 0x00007f0c305d60eb in g_main_context_pending () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#11 0x000055e21e68e8fc in gui_mch_update () at gui_gtk_x11.c:6624
#12 0x000055e21e622925 in ui_breakcheck_force (force=0) at ui.c:706
#13 ui_breakcheck () at ui.c:681
#14 0x000055e21e4cb09d in vgetorpeek (advance=advance@entry=1) at getchar.c:3499
#15 0x000055e21e4cd6cc in vgetc () at getchar.c:1939
#16 0x000055e21e604a62 in term_vgetc () at terminal.c:2381
#17 0x000055e21e60cef6 in terminal_loop (blocking=blocking@entry=1) at terminal.c:2845
#18 0x000055e21e49ac42 in exec_normal (was_typed=was_typed@entry=1, use_vpeekc=use_vpeekc@entry=0,
    may_use_terminal_loop=may_use_terminal_loop@entry=1) at ex_docmd.c:9331
#19 0x000055e21e472b7f in f_feedkeys (argvars=<optimized out>, rettv=<optimized out>) at evalfunc.c:4754
#20 0x000055e21e479275 in call_internal_func (name=<optimized out>, argcount=<optimized out>, argvars=0x7fff6934bc40,
    rettv=0x7fff6934be50) at evalfunc.c:3280
#21 0x000055e21e637781 in call_func (funcname=funcname@entry=0x55e257257420 "feedkeys", len=len@entry=-1,
    rettv=rettv@entry=0x7fff6934be50, argcount_in=argcount_in@entry=2, argvars_in=argvars_in@entry=0x7fff6934bc40,
    funcexe=funcexe@entry=0x7fff6934bf70) at userfunc.c:4017
#22 0x000055e21e637afa in get_func_tv (name=name@entry=0x55e257257420 "feedkeys", len=len@entry=-1,
    rettv=rettv@entry=0x7fff6934be50, arg=arg@entry=0x7fff6934be30, evalarg=evalarg@entry=0x7fff6934bee0,
    funcexe=funcexe@entry=0x7fff6934bf70) at userfunc.c:2039
#23 0x000055e21e63883f in ex_call_inner (eap=0x7fff6934c2d0, name=0x55e257257420 "feedkeys", arg=0x7fff6934be30,
    startarg=0x55e25729a74f "(\"\\<C-W>N\", 'xt')", funcexe_init=0x7fff6934be80, evalarg=0x7fff6934bee0) at userfunc.c:6228
#24 ex_call (eap=0x7fff6934c2d0) at userfunc.c:6576
#25 0x000055e21e49ec0c in do_one_cmd (cmdlinep=0x7fff6934c230, flags=7, cstack=0x7fff6934c480,
    fgetline=0x55e21e62e820 <get_func_line>, cookie=0x55e25724f9e0) at ex_docmd.c:2616
#26 do_cmdline (cmdline=cmdline@entry=0x0, fgetline=fgetline@entry=0x55e21e62e820 <get_func_line>,
    cookie=cookie@entry=0x55e25724f9e0, flags=flags@entry=7) at ex_docmd.c:1028
#27 0x000055e21e63691e in call_user_func (fp=fp@entry=0x55e25720f670, argcount=argcount@entry=0,
    argvars=argvars@entry=0x7fff6934d2b0, rettv=<optimized out>, funcexe=<optimized out>, selfdict=selfdict@entry=0x0)
    at userfunc.c:3202
#28 0x000055e21e636e72 in call_user_func_check (fp=0x55e25720f670, argcount=0, argvars=0x7fff6934d2b0, rettv=0x7fff6934d4c0,
    funcexe=0x7fff6934d5e0, selfdict=<optimized out>) at userfunc.c:3375
#29 call_user_func_check (fp=0x55e25720f670, argcount=0, argvars=0x7fff6934d2b0, rettv=0x7fff6934d4c0, funcexe=0x7fff6934d5e0,
    selfdict=<optimized out>) at userfunc.c:3329

It seems gui_mch_update() may sometimes run into an endless loop. I can reproduce it, if I do not cause any activities in X11.
So we may need an additional condition like this:

diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index c037702ad..44ec848b5 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -6621,7 +6621,8 @@ gui_mch_draw_part_cursor(int w, int h, guicolor_T color)
     void
 gui_mch_update(void)
 {
-    while (g_main_context_pending(NULL) && !vim_is_input_buf_full())
+    int cnt = 0;       // prevent endless loop
+    while (g_main_context_pending(NULL) && !vim_is_input_buf_full() && ++cnt < 100)
        g_main_context_iteration(NULL, TRUE);
 }

Does that make sense? I hope.

@h-east
Copy link
Copy Markdown
Member Author

h-east commented Dec 15, 2024

@chrisbra Thanks for digging into the CI error.
I don't have an environment where I can reproduce this phenomenon, so let me ask a question.

  • After the count is over and the loop is exited, is there a trigger that causes g_main_context_pending(NULL) to return FALSE?
  • Is it okay if the judgment is not based on the passage of time, like in the code below?

vim/src/gui_gtk_x11.c

Lines 7035 to 7040 in 6e19993

// Hack: Wait up to three seconds for the selection. A hang was
// noticed here when using the netrw plugin combined with ":gui"
// during the FocusGained event.
start = time(NULL);
while (received_selection == RS_NONE && time(NULL) < start + 3)
g_main_context_iteration(NULL, TRUE); // wait for selection_received_cb

@chrisbra
Copy link
Copy Markdown
Member

Honestly, I don't know. I just wanted to make sure the loop is properly cancelled in case of both of the other conditions keep returning "TRUE". We may as well use the example code you showed, I just thought the counter would be a bit easier.

@h-east
Copy link
Copy Markdown
Member Author

h-east commented Dec 15, 2024

Ok, let's go with your fix.
Should I include it in the PR?

chrisbra pushed a commit that referenced this pull request Dec 15, 2024
Problem:  tests: test_terminal2 may hang in GUI mode
Solution: break the loop in gui_mch_update() after at most 99 iterations
          (h-east)

related: #16211

Signed-off-by: h-east <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
@chrisbra chrisbra closed this in 3a3a2c9 Dec 15, 2024
@h-east h-east deleted the fix-termwin-issue branch December 16, 2024 00:41
@user202729
Copy link
Copy Markdown
Contributor

Are you sure the issue is fixed? I'm using vim 9.1 with included patches 1-1043 and the reproduce instruction in #16024 still gives the error for me.

(sanity check, this PR is patch 9.1.0930 which is included there right?)

@h-east
Copy link
Copy Markdown
Member Author

h-east commented Jan 31, 2025

Perhaps, patch 9.1.0931
3a3a2c9

@chrisbra
Copy link
Copy Markdown
Member

It might be a different error, but we would need more details

@user202729
Copy link
Copy Markdown
Contributor

I can reproduce it with the exact same instructions as in #16024 (comment)

Video for demonstration:
https://github.com/user-attachments/assets/3548d9f4-8007-46af-b6b8-a678b0d8e1fe

@h-east
Copy link
Copy Markdown
Member Author

h-east commented Jan 31, 2025

I couldn't reproduce the problem by writing a test using the exact steps, so I found a pattern where the error occurred in a different step and wrote a test and patch. However, it seems that this only fixed a different problem.
I'll investigate again.

chrisbra pushed a commit that referenced this pull request Feb 1, 2025
Problem:  terminal: E315 when dragging the terminal with the mouse
          (user202729)
Solution: call update_topline() and validate_cursor() when clicking
          on the status line with the mouse (Hirohito Higashi)

fixes: #16024
fixes: #16211
closes: #16552

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
chrisbra pushed a commit that referenced this pull request Apr 21, 2025
Problem:  may receive E315 in terminal
Solution: call check_cursor() (Hirohito Higashi)

fixes: #16024
fixes: #16211
fixes: #17099
closes: #17170

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E315 ml_get:invalid_lnum: [number] in terminal buffer [again]

3 participants