After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 542087 - Graphical glitches after "change scroll region"
Graphical glitches after "change scroll region"
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
[fixed-0-36][needed-next][commit:88e8...
: 686097 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-07-08 17:52 UTC by Micah Cowan
Modified: 2015-12-26 13:03 UTC
See Also:
GNOME target: ---
GNOME version: 2.21/2.22


Attachments
Reproduction script (871 bytes, text/plain)
2008-07-08 17:57 UTC, Micah Cowan
  Details
scrollregion.sh demonstrates the bug (2.52 KB, text/plain)
2010-10-20 15:42 UTC, Todd Lewis
  Details
scrollseba.sh Another demo of the bug (1.69 KB, text/plain)
2010-10-20 15:44 UTC, Todd Lewis
  Details
Patch to work around update glitch; applies against vte-0.26.0 and vte-0.23.5 (3.08 KB, patch)
2010-12-01 07:05 UTC, Micah Cowan
none Details | Review
Revised patch (3.16 KB, patch)
2010-12-08 04:19 UTC, Micah Cowan
committed Details | Review
Slight modification of Todd's script, to improve odds of processing the codes together. (2.55 KB, text/plain)
2010-12-15 07:34 UTC, Micah Cowan
  Details

Description Micah Cowan 2008-07-08 17:52:49 UTC
Please describe the problem:
After sending CSR so that the final line in the terminal is excluded from the scroll region, glitches can occur when interspersing writes to the bottom line with scrolls of the upper region.

Steps to reproduce:
I will attach a script (scr-fix-min) that produces the problem for me.

Actual results:
What I currently see: one or both of "foo" and "bar" are missing. Or, on at least one system, the bar will be black/empty when it ought to be reversed/have-text.

Actually, when I _should_ see "foo" and "bar", but don't, I will sometimes actually see an effect such that it looks like the top one or two pixel-rows of the bottom line update and switch back, but not the rest of the line. So a masking problem or incorrect information about what portions of the display to update seem likely.

Expected results:
What you ought to see: the bottom bar flash between "x", "foo", "x", and "bar".

Does this happen every time?
This reproduces reliably for me on gnome-terminal. xfce4-terminal sometimes shows both "foo" and "bar" as it ought to, and sometimes doesn't (same app, same instance, different runs of script).

Other information:
This behavior was discovered while I was using screen, which can use the final line as a "status" line. I was playing with screen's "autoaka" feature, which allows the current screen window's name to change based on the currently-running command: I found that everything worked as it should until the prompt reached the  bottom, so that hitting enter caused scrolling. At that point, the window title would stop updating.
Comment 1 Micah Cowan 2008-07-08 17:57:25 UTC
Created attachment 114201 [details]
Reproduction script

This script expects LINES and COLUMNS to be exported and refer to the number of lines and columns in your terminal. These must be accurate or the bug won't be shown. If they are unset, you will get a ton of errors, rather than the simulation.
Comment 2 Micah Cowan 2008-07-08 17:58:11 UTC
For a history of my attempt to track down this problem on screen's bug-tracker at Savannah, see https://savannah.gnu.org/bugs/?23699
Comment 3 Sebastiano Vigna 2010-01-25 18:07:12 UTC
The same problem shows with ne (the nice editor: http://ne.dsi.unimi.it/). When scrolling down, line/column numbers are not updated. Scrolling happens using a scroll region. 

If scrolling is done by manual rewrite, the problem does not appear. 

The problem does not appear in any other terminal (xterm, Mac terminal, rxvt, etc.).

I have pinpointed very carefully the problem by looking at vim. Essentially, if you do the following on an 80x25 terminal:

1) Set scroll region 1-24
2) Move to pos (24,1)
3) Issue a line feed to scroll the region
4) Set scroll region 1-25 (full screen)
5) Move to pos (24,1)
6) Update line 24 (now empty)
7) Move to pos (25,4)
8) Update lines/cols

the last step causes NO OUTPUT (bug, bug, bug...). However, if you do

8) Emit a clear-to-eol and update lines/cols

this works. Emitting a clear-to-eol seems to reset the broken state of gnome-terminal.
Comment 4 Christian Persch 2010-01-25 18:12:03 UTC
Which vte version?
Comment 5 Sebastiano Vigna 2010-01-25 18:13:37 UTC
gnome-terminal 2.26.3.1
Comment 6 Behdad Esfahbod 2010-01-25 18:59:42 UTC
Care to provide exact instructions for reproducing?
Comment 7 Micah Cowan 2010-01-25 19:55:42 UTC
Precise instructions were provided with the original report. Please download the attached bash script, do "export LINES COLUMNS", and then run the script with bash. Watch the bottom (reversed) line; you ought to see it flash between "foo", "x", "bar", "x", but instead I just see "x" the whole time (compare results with another term, such as xterm, to see what it is meant to look like). The glitch doesn't always manifest as "seeing x the the whole time", see the "Actual results" section of the original report.

I'm still seeing this with libvte9 0.22.2(-0ubuntu2), on gnome-terminal 2.28.1.
Comment 8 Sebastiano Vigna 2010-01-25 19:57:49 UTC
Start ne (http://ne.dsi.unimi.it/), open a file with more lines than the terminal rows. Move down: when the file scrolls the line number does not change. It does as soon as you move the cursor on the right.

Again, if you emit a clear-to-eol just before printing the line numbers (as vim does, for instance) everything works fine.

You can see what ne is doing starting with "ne | tee ne.out".

It you add the function call clear_to_eol(); at the start of line 660 of the source file menu.c you'll see that line numbers are now updated.
Comment 9 Behdad Esfahbod 2010-02-26 06:18:47 UTC
Ok, I reproduced the missing 'foo' twice out of like 20 or 30 tries.
Comment 10 Sebastiano Vigna 2010-07-30 05:44:06 UTC
Well, if that's reproduced why is it that after six months the bug is still "unconfirmed"? ;)
Comment 11 Todd Lewis 2010-10-20 15:40:29 UTC
(In reply to comment #9)
> Ok, I reproduced the missing 'foo' twice out of like 20 or 30 tries.

There is a timing component to this bug. I have modified Micah Cowan's script to accept a "-s" parameter (for "slow") which introduces a 1 second delay immediately after updating the line below the scroll region. This causes the status line update to succeed every time. (See attachment scrollregion.sh.)

I've also created a similar script which exactly follows the steps outlined by Sebastiano Vigna in comment #3. This script also takes an optional "-s" (for "slow") parameter, which causes the script to succeed every time. (See attachment scrollseba.sh.)

I've also discovered that moving/dragging the mouse around a lot over the window tends to make these scripts succeed slightly more often. I suspect this increased activity is enough to tickle the timing dependency somewhat, at least on my system. C code doing the same thing though is so much faster than these shell scripts that no amount of mouse movement has caused the status line updates in "ne" to succeed (see comment #8).
Comment 12 Todd Lewis 2010-10-20 15:42:25 UTC
Created attachment 172851 [details]
scrollregion.sh demonstrates the bug
Comment 13 Todd Lewis 2010-10-20 15:44:05 UTC
Created attachment 172852 [details]
scrollseba.sh Another demo of the bug

With the "-s" (for "slow") parameter, these scripts succeed. At full speed they often fail.
Comment 14 Micah Cowan 2010-12-01 07:05:44 UTC
Created attachment 175605 [details] [review]
Patch to work around update glitch; applies against vte-0.26.0 and vte-0.23.5

Found the source of the problem. The vte_terminal_process_incoming function from vte.c keeps track of a "bounding box" of cells to be invalidated, and uses that to invalidate cells at points such as after all input has been processed, or when a large enough cursor jump is made (to avoid letting the bounding box get needlessly large). This bounding box is represented in terms of the total number of lines in the terminal, including history. The problem that arises is that if a scroll takes place before the bounding box has been used to invalidate cells, then a new row is added to the total terminal rows, increasing the index number of the bottom rows. Thus, the bounding box will now be off by one (or however large the scroll is), and no longer reaches all the way to the bottom of the screen (if it did before). This problem applies, even when no scrollback history is enabled, as the relevant indexes all still increase, even though the true number of actual data rows hasn't changed.

The fix I implemented is to force invalidation to take place if we move into a scroll region from outside it.
Comment 15 Micah Cowan 2010-12-08 04:19:30 UTC
Created attachment 176035 [details] [review]
Revised patch

One-line addition to force the cached scroll_delta value to be refreshed after control sequences are handled; fixes this same problem in a few cases apparently not handled by the automated test scripts.
Comment 16 Behdad Esfahbod 2010-12-08 04:31:13 UTC
Humm, attached the wrong patch?
Comment 17 Micah Cowan 2010-12-09 05:49:25 UTC
No? To be clear, I meant I made a one-line addition, but attached a complete, revised diff.
Comment 18 Behdad Esfahbod 2010-12-09 18:34:06 UTC
Ah, ok.  So the fix is not a one-line patch...
Comment 19 Micah Cowan 2010-12-09 19:11:34 UTC
Ah, no, sorry for the confusion. But it is about 10 lines (3 of which are repeats), not including simple whitespace changes, and should be pretty straightforward.
Comment 20 Behdad Esfahbod 2010-12-15 05:41:21 UTC
I actually see the expected result with latest vte, the same as what I see in xterm.  Have you tried this with latest vte?
Comment 21 Micah Cowan 2010-12-15 07:09:48 UTC
What's "latest"? 0.27, or current dev sources? If the latter, where do I find those?

I've reproduced in 0.26 (which is the version currently used by my laptop); I guess I can try 0.27.
Comment 22 Micah Cowan 2010-12-15 07:33:09 UTC
Actually, I can't; it's dependencies (mainly gtk+3) are a bit beyond what I'm willing to put on this machine (Ubuntu Maverick) just at the moment (Ubuntu Natty has it; perhaps I'll upgrade soon). Looking at the sources, though, I see no reason why the problem wouldn't still persist.

Since I had discovered the source of the problem requires that both the write to the bottom line and the scroll in the scroll region be processed as part of the same invocation of vte_terminal_process_incoming(), and you (Behdad) have had persistent difficulties in reproducing it as easily as some others (Todd's "scrollregion.sh" script is especially consistent for me, with only occasional successes of a single one of the ten iterations), it may help if the reproduction script forces it all to be written at once (to the degree possible). I modified Todd's script slightly, so that the output of a single iteration (multiple calls to tput, etc) is stored in a variable, which is then spewed by a single printf. See if this gets you any further? I'll call it "scrollregion-spew.sh".
Comment 23 Micah Cowan 2010-12-15 07:34:49 UTC
Created attachment 176443 [details]
Slight modification of Todd's script, to improve odds of processing the codes together.

-s is still accepted, but is ignored, since there's no longer a point to it in this version.
Comment 24 Micah Cowan 2010-12-15 07:35:15 UTC
(Er, yeah, I mistakenly marked that as a "patch". Anyhoo...)
Comment 25 Micah Cowan 2010-12-15 07:51:29 UTC
Double-checking the source, I can guarantee that the problem's still there in 0.27.2, since the same logic flaws addressed by my patch are still present (see the explanation from the first patch I attached), and in fact the function in question was never changed since 0.26.0. No other function could know of the inserted characters, to refresh them; so if this function hasn't changed, neither has the glitch. The only other way the glitch could be removed would be for something to be inadvertently causing it to be refreshed there anyway; but _vte_terminal_cursor_down still only refreshes the scroll region, not the full terminal, so I don't really see where that could happen.
Comment 26 Christian Persch 2010-12-15 10:30:54 UTC
(In reply to comment #22)
> Actually, I can't; it's dependencies (mainly gtk+3) are a bit beyond what I'm
> willing to put on this machine (Ubuntu Maverick) just at the moment

vte does NOT depend on gtk3 (which is only an option; the default is still to build with gtk2).
Comment 27 Micah Cowan 2010-12-15 17:19:38 UTC
Ah, apparently the Debian package (I was using it to build, but with patches stripped out) runs the configure script more than once (for some reason). I only paid attention to the options provided for the first invocation; the second appears to use --with-gtk=3.0, so that would explain my problem. I'll see if I can give it a try tonight.
Comment 28 Behdad Esfahbod 2010-12-15 23:51:56 UTC
Thanks Micah.  The new script reliably reproduces the problem for me.  Fixing.
Comment 29 Todd Lewis 2011-10-31 02:35:36 UTC
(In reply to comment #28)
> Thanks Micah.  The new script reliably reproduces the problem for me.  Fixing.

I'm confused. Ten months later, this bug is still marked UNCONFIRMED, and the fix didn't make it into GNOME 3, at least as shipped with Fedora-15. Did this fall through the cracks, or was the fix rejected for some reason, or what?
Comment 30 Egmont Koblinger 2013-10-18 22:16:34 UTC
Behdad/ChPe, could you please apply Micah's patch?

The bug is valid, and the patch indeed seems to fix it. The patch has been shipped by Ubuntu since Precise (12.04 LTS) so it must be very well tested by now.
Comment 31 Egmont Koblinger 2013-10-18 22:21:26 UTC
Note that there's another minor bug revealed by the test script (and not yet fixed): the scrollbar is positioned incorrectly.
Comment 32 Egmont Koblinger 2013-10-19 01:44:45 UTC
The previously mentioned bug, and a few other relevant ones [with patches] are filed at bug 710488, bug 710484, bug 710483 and bug 710481 -- so that we can keep this one clean, for the original report only.
Comment 33 Egmont Koblinger 2013-10-19 19:22:51 UTC
*** Bug 686097 has been marked as a duplicate of this bug. ***
Comment 34 Christian Persch 2013-11-17 21:25:18 UTC
Committed to vte-0-36.

I wonder if we need to do the same when the cursor moves out of the restricted scrolling area? Ie sth like this:

 /* if we have moved greatly during the sequence handler, or moved
- * into a scroll_region from outside it, restart the bbox.
+ * into/out of a scroll_region from out/inside it, restart the bbox.
  */
 if (invalidated_text &&
-    ((new_in_scroll_region && !in_scroll_region) ||
+    ((new_in_scroll_region ^ in_scroll_region) ||
Comment 35 Christian Persch 2015-12-26 13:03:21 UTC
Fixed on 0-36, therefore on master too.