Tk Source Code

View Ticket
Login
Ticket UUID: f79ed9db4ae86228292b0d1d13e36d3d5867f520
Title: Repainting issue with 8.6.11-rc on High Sierra
Type: Bug Version: 8.6.11-rc
Submitter: anonymous Created on: 2020-12-17 07:15:38
Subsystem: 66. Aqua Window Operations Assigned To: marc_culler
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2021-05-25 02:01:36
Resolution: Works For Me Closed By: marc_culler
    Closed on: 2021-05-25 02:01:36
Description:
If a text widget is scrolled quickly in alternating directions, it does not repaint correctly on macOS High Sierra with the lates build of 8.6.11-rc. This is a regression, it works with 8.6.9

Code:
==========

package require Tk

pack [button .b -text "Click me to get the focus out" -command {focus .b}]
pack [text .t]

for {set i 0} {$i<200} {incr i} {
	.t insert end "\n Line$i"
}

Result:
=================
https://youtu.be/e6V8GP7Jrpw
User Comments: marc_culler (claiming to be Marc Culler) added on 2021-05-25 02:01:36:
I tested this with the current core-8-6-branch on Big Sur and could not
reproduce anything like the artifacts shown in the youtube video.  I
think this problem disappeared with the switch to an explicit CALayer-
backed NSView.

I am closing this ticket.  If the problem still exists, please reopen the
ticket.

chrstphrchvz added on 2021-01-21 08:26:29:

Since mac_lockfocus didn't help, I wondered if this issue is due to a clipping problem. But I am actually having difficulty confirming anything is drawn at all only with lockFocus and not while in drawRect:.


bll added on 2021-01-17 18:03:34:
On High Sierra, I can only generate artifacts using Christopher's button.
When scrolling, I may see artifacts briefly, but they resolve themselves
after a short delay.
(using mac_styles branch).

chrstphrchvz added on 2021-01-17 14:31:42:

Although the mac_lockfocus branch ([87d589d585]) restores lockFocus usage on macOS 10.13 and older, which I also thought might help, I still observe this issue using it.


chrstphrchvz added on 2021-01-17 12:26:20:

This issue reminds me of the one reported several months ago on tcl-mac: https://sourceforge.net/p/tcl/mailman/tcl-mac/thread/b58e3ba3-95c3-f280-97d7-ffb0526d65fa%40brandeis.edu/. But the reporter of that issue observed it on macOS 10.15 as well, and believed it was resolved between Tk 8.6.10 and 8.6.11.


chrstphrchvz added on 2020-12-19 19:19:16:

If I add a button:

pack [button .b2 -text {scroll .t} -command {
        after 400 {
                .t yview scroll 13 pixels
                after idle {.t yview scroll 13 pixels}
        }
}]

When clicking on this button, I reliably observe that the line at the bottom will be moved up by 26 pixels, but the line after it will look as if it has duplicated the line before it.

Bottom 5 lines before/after one click/after two clicks:
                 

One hypothesis making this a separate issue from [2a61eca3a8]: Tk is incorrectly assuming when things have been drawn to screen—or to the backing store, more precisely—and so are safe to be moved around with scrollRect:by:. I imagine this sequence of events happening:

  1. Start outside of drawRect:.
  2. A text scroll command causes lines not already completely onscreen to be scheduled to be drawn.
  3. Idle events are handled, including the first attempt at redrawing the lines exposed by the text scroll command. Since this is outside of drawRect, nothing is drawn into the backing store, although the lines think they have been completely drawn.
  4. A second scroll command occurs: it tries using scrollRect:by: (which works while outside of drawRect:) to move the lines that were supposed to be drawn by the first scroll command. But those lines haven't been drawn to the backing store, so what was instead moved was stale drawing.
  5. Eventually enter drawRect:, which does draw lines needed as of the second scroll command, but does nothing to fix the artifacts.

I don't know how I would want to fix this, if this is indeed the correct explanation. I guess reverting to lockFocusIfCanDraw/unlockFocus usage is one possibility on 10.13 High Sierra and earlier.

But I'm sometimes also seeing artifacts where entire lines are the background color of the frame, rather than portions of text. I don't have an explanation for this, or why I haven't yet observed this issue on 10.15 Catalina.


chrstphrchvz added on 2020-12-19 16:20:36:

I am very curious about why changing the default font from one fixed pitch font (SF Mono, I think) to another (Menlo, I think) would cause the text widget to no longer scroll by exactly one line at a time. Can you explain that?

I observe that the <MouseWheel> binding scrolls the text vertically by 15 pixels at a time. The default font previously had a "height" of 15 pixels per line, whereas it is now 13 pixels.


marc_culler (claiming to be Marc Culler) added on 2020-12-19 14:19:42:
Hi Christopher, while I think it is a side issue, I am very curious about
why changing the default font from one fixed pitch font (SF Mono, I think)
to another (Menlo, I think) would cause the text widget to no longer scroll
by exactly one line at a time.  Can you explain that?

One thing that occurs to me as a workaround for this problem would be to try
switching back to drawing the entire window for every update on High Sierra,
or perhaps on all systems that predate the current Dark Age of Apple.  Another,
possibly better and simpler approach might be to try to avoid the failed
draws by calling [NSView lockFocus] on those systems where that call is not deprecated.

It is clear that the basic mechanism which leads to certain regions not being
drawn after [83479bd9ac] is that the region lies outside of the clipping
rectangle passed to drawRect.  But my testing showed that is not happening in
[2a61eca3a8]. It would be helpful if someone who can reproduce this problem 
could test if that is the cause here.  By the way, my tests only checked
whether the drawing was taking place inside the bounding rectangle of the
clipping region, which of course is not the whole story since the actual
clipping region is a rectangle with subrectangles cut out of it for child
windows.

The fact that the behavior occurs on some OS versions and not others, and that
it also depends on the hardware, suggests to me that it is timing-related.  But
that does not explain the mechanism.  I am leaning towards thinking it involves
clipping regions somehow.

chrstphrchvz added on 2020-12-19 12:33:14:

I am inclined to think this resembles [83479bd9ac]

I meant [2a61eca3a8]


chrstphrchvz added on 2020-12-19 12:32:03:

The issue appears starting with [83479bd9ac], when setNeedsDisplayInRect: was first used instead of setNeedsDisplay:YES. I believe this is not easily revertible due to extensive related changes made since then.

I am inclined to think this resembles [83479bd9ac], where lines of text are scheduling to redraw separately, but then fail to draw (e.g. by attempting to draw during the wrong drawRect: call), leaving behind stale drawing artifacts. It happens to be worsened by the text widget's use of scrollRect:by: which allows artifacts to persist and move around after additional scrolling.

Note: due to a nearby change [c7ede02aa0], text using the default font is no longer scrolled by exactly one line at a time (not sure if this should be considered a regression), so the artifacts of non-redrawn lines became much easier to spot. It helps to use some pattern that alternates horizontally, e.g.

for {set i 0} {$i<200} {incr i} {
	.t insert end "\n Line$i"
	incr i
	.t insert end "\n     Line$i"
}


chrstphrchvz added on 2020-12-19 08:18:56:

Using the latest core-8-6-branch ([9fa0e54697]), I can reproduce this issue on my MacBook Pro 2010 13 inch under High Sierra, but not Catalina.


anonymous (claiming to be auriocus) added on 2020-12-17 18:59:53:
Another note on reproducing the issue: It is not just the fast scrolling, but it happens if the direction is changed. i.e. scroll down a little bit, then scroll back. Like on the touchpad do a v-sign. 

Too bad if it is not reproducible :(, it must be something on my system then.

nab added on 2020-12-17 18:20:02:
Hi,
tested with a 2days old Tcl core8-6 branch and mac_styles branch on a MBP running macOS11.1
no issues with the provided script

++

marc_culler (claiming to be Marc Culler) added on 2020-12-17 17:47:42:
I have now tested on the five macOS systems listed below using the script
from this ticket.  None of these systems showed any artifacts when scrolling
the text widget.  I could not reproduce the issue that is visible in the video.

* Macbook Air (Retina 13-inch, 2019) running macOS 11.1 (Big Sur)
* Mac mini (late 2014) running macOS 10.15.7 (Catalina)
* VMWare Fusion 12 VM running macOS 10.14.4 (Mojave)
* VMWare Fusion 12 VM running macOS 10.13.6 (High Sierra)
* VMWare Fusion 12 VM running macOS 10.12.6 (Sierra)
 
The tests were done using commit 9fa0e546977 of Tk and commit 4b11e2417a
of Tcl from the core-8-6-branches.

(It is important to test with a relatively recent Tcl commit because the
macOS implementation of Tcl_WaitForEvent changed during the last year.)

To do extra fast scrolling on the mini and VMs I reconnected my mighty
mouse, after carefully cleaning its track ball with alcohol.  That usually
makes it work for a couple of days, and it does do very fast scrolling.

I am reluctant to call this a won't-fix -- clearly the problem exists on
at least one machine in some context and I would like it to be fixed --
but I see no way that I could fix it without being able to reproduce it.
I do think it would be wise to build the latest core-8-6-branch Tcl and
Tk and retest, making certain that those builds are really being used for
the test. Incidentally, I am aware of similar scrolling issues reported
to me last May for a 2020 Macbook Pro running macOS 10.15. But those were
fixed.

Can anyone else reproduce this?

marc_culler (claiming to be Marc Culler) added on 2020-12-17 14:31:44:
These scrolling artifacts do not appear on Big Sur (11.1), no matter how fast
I scroll.  I will test on other OS versions.  I have Catalina on hardware,
but will have to test other releases on VMs.

(Side note: It looks like Apple will now increase the major number with each
new annual release name, and use the minor number for incremental updates, like
everyone else does. Eleven is not as magical as ten, evidently.)

Another note: macOS 10.13 is the newest version of macOS that will run on
a system whose graphics hardware does not support the Metal language, without
making modifications that Apple does not support.  Also it is the last OS
version which does not support "dark mode".  Hardware requirements for 10.14
are:

 MacBook     (Early 2015 or newer)
 MacBook Air (Mid 2012 or newer)
 MacBook Pro (Mid 2012 or newer)
 Mac mini    (Late 2012 or newer)
 iMac        (Late 2012 or newer)
 iMac Pro    (2017)
 Mac Pro     (Late 2013; Mid 2010 and Mid 2012 models with recommended
              Metal-capable graphics cards).