| Ticket UUID: | 415415 | |||
| Title: | Long callback: One click -> Two steps | |||
| Type: | Bug | Version: | obsolete: 8.3.3 | |
| Submitter: | dgp | Created on: | 2001-04-11 15:02:11 | |
| Subsystem: | 15. [scale] | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2022-04-07 06:32:36 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2022-04-07 06:32:36 | |||
| Description: |
Evaluate the demo script in wish. Click once in the trough of the scale. Do not hold the button down. Watch the scale advance two steps. This problem can be worked around by configuring the -repeatdelay of the scale, but that's not obvious from the documentation pages. Documentation improvements are probably sufficient to close this bug. | |||
| User Comments: |
fvogel added on 2022-04-07 06:32:36:
Merged into core-8-6-branch and trunk. fvogel added on 2022-03-30 20:22:10:
> The only remaining question is for you, dgp: how come that you see test > scale-18.4 pass on unpatched Tk? This does not match my observations. I have confirmed that test scale-18.4 passes on all platforms (see test output at Github for branch bug-415415fff) and that it fails without the fix (see test output at Github for branch bug-415415fff-nofix). Unless someone can show evidence of any different behaviour I will merge the fix and close this ticket in a few days. fvogel added on 2022-03-28 20:30:55: The differences I was seeing between my setup and GitHub was due to me running only scale.test while GitHub runs the entire test suite. Conclusion: the problem is interaction between two (or more tests). After some time identifying which test made scale-18.4 fail, the problem became clear (variable x1 was used in both tests but was not unset at the end of the first test). Improving test suite hygiene in [ee1da9efa3] fixes this problem. The only remaining question is for you, dgp: how come that you see test scale-18.4 pass on unpatched Tk? This does not match my observations. fvogel added on 2022-03-19 22:50:05: Thanks for your comments. Test name changed into scale-18.4. But that was the easy part. I have tried to reproduce the bug on X11 (local physical laptop running Debian 10) and Aqua (macOS Catalina accessed through VNC on Brad Lanam's mac). Indeed with the original test script you have provided the bug is not reproducible for me either. However, for me on those two platforms (and also on Win 10) the new test scale-18.4 fails without the fix and passes with the fix. I.e. exactly as it should be. I have no idea why you are seeing the test passing without the fix, what do you think of this? Another puzzling thing is at GitHub Actions: there, with the fix in use, scale-18.4 fails on all three platforms. What GitHub reports is not consistent with what I'm seeing when I run the test myself and I have no clue why. dgp added on 2022-03-16 15:44:39: Thanks for the continued work on this. A few observations. For now, my convenient testing platforms are limited to X11 and Aqua on Mac OSX. On those systems the bug isn't reproducible. The test passes on unpatched Tk. The test name scale-18.3 is already in use, so when this gets wrapped up and ready to merge, be sure to choose an unused name fvogel added on 2022-03-14 22:04:56: I have added non-regression test scale-18.3, failing before the fix, and passing after the fix. See [811b9f15]. fvogel added on 2022-03-02 07:06:56: There is no need for any special or old platform, just use your preferred one today and you'll be able to see the issue and whether it's fixed. Comments on the way I have dealt with this also welcome, thanks! dgp added on 2022-02-28 18:55:43: Thanks for working on this. I'm sure I don't have the platform any more where I originally observed the problem. Your tests should be as good as mine could be. fvogel added on 2022-02-25 23:22:22: Revisiting this ticket with fresh ideas I now understand what's going on. When clicking in the trough of the scale, ::tk::ScaleIncrement gets called and runs "$s set ...." and ::tk::ScaleIncrement shedules itself after -repeatdelay. This "$s set ...." command schedules an idle redraw of the scale during which the -command script gets run. When the mouse button is released, this event is queued. If the -command script lasts longer than -repeatdelay, when servicing the event loop, the button release event is not yet seen when reentering ::tk::ScaleIncrement, causing the -command script to be run a second time even if the mouse button was released a long time ago. I have committed a fix for this, see branch bug-415415fff. dgp, could you please test on your side and see whether this satisfies the need? Thanks! fvogel added on 2016-08-17 20:44:27: Investigating a bit by instrumenting:
- on Linux: TransferXEventsToTcl()
- on Windows: TkTranslateWinEvents()
in order to printf when a ButtonPress and ButtonRelease is received at the Tcl/Tk level.
On Linux, the ButtonRelease event is always received by Tk from the OS before tk::ScaleIncrement is reentered, i.e. before
after $delay [list tk::ScaleIncrement $w $dir $big again]
gets executed by the event loop.
Then, the binding to the ButtonRelease event cancels the repeat, and it works.
On Windows this does not happen. The ButtonRelease event (WM_BUTTONUP) shows up too late. It really looks like to OS does not provide the event quickly enough.
fvogel added on 2016-08-15 20:56:38: I can still see this on Windows Vista, with both core-8-6-branch and trunk. However, I could not reproduce when the toplevel showing the scale widget already has the focus at the time of clicking on the trough. It reproduces often (not always) when first clicking elsewhere on the desktop (to remove the focus from the Tk toplevel showing the scale widget), and then clicking directly in the trough. On what platform did you see this originally? dgp added on 2016-08-15 19:19:25: Can no longer reproduce. Something fixed it along the way it seems. fvogel added on 2016-08-15 13:06:19: Cannot see the problem on Debian 8. Preivous analysis from me was on Vista. fvogel added on 2014-11-08 09:22:28: For the records, in case someone wants to take this over, here is my instrumented script (copy and paste in wish):
catch {destroy .s}
scale .s -from 0 -to 10 -length 200\
-orient horizontal -label "TITLE"\
-tickinterval 1 -showvalue true\
-command Doit
pack .s
proc Doit { value } {
puts "Doit: arg is $value"
after 1000
puts "Doit: Done $value"
}
# Now instrumented stuff replacing those from scale.tcl and from tk.tcl
proc ::tk::CancelRepeat {} {
variable ::tk::Priv
puts "Cancelling"
after cancel $Priv(afterId)
set Priv(afterId) {}
}
bind Scale <1> {
puts "\n\n<1> fires"
tk::ScaleButtonDown %W %x %y
puts "end of <1>"
}
proc ::tk::ScaleIncrement {w dir big repeat} {
variable ::tk::Priv
puts "Entering ScaleIncrement: $repeat"
if {![winfo exists $w]} return
if {$big eq "big"} {
set inc [$w cget -bigincrement]
if {$inc == 0} {
set inc [expr {abs([$w cget -to] - [$w cget -from])/10.0}]
}
if {$inc < [$w cget -resolution]} {
set inc [$w cget -resolution]
}
} else {
set inc [$w cget -resolution]
}
if {([$w cget -from] > [$w cget -to]) ^ ($dir eq "up")} {
if {$inc > 0} {
set inc [expr {-$inc}]
}
} else {
if {$inc < 0} {
set inc [expr {-$inc}]
}
}
puts "SETting the value: [expr {[$w get] + $inc}]"
$w set [expr {[$w get] + $inc}]
puts "Rescheduling"
if {$repeat eq "again"} {
set Priv(afterId) [after [$w cget -repeatinterval] \
[list tk::ScaleIncrement $w $dir $big again]]
} elseif {$repeat eq "initial"} {
set delay [$w cget -repeatdelay]
if {$delay > 0} {
set Priv(afterId) [after $delay \
[list tk::ScaleIncrement $w $dir $big again]]
}
}
}
Test case 1: Copy and paste in wish, click in the trough. The output shows one run too much of ScaleIncrement, i.e. cancelling shows up too late, as follows:
<1> fires
Entering ScaleIncrement: initial
SETting the value: 1.0
Rescheduling
end of <1>
Doit: arg is 1
Doit: Done 1
Entering ScaleIncrement: again
SETting the value: 2.0
Rescheduling
Cancelling
Doit: arg is 2
Doit: Done 2
Test case 2: Copy and paste in wish, click in the toplevel to let it have focus, click in the trough. The output shows correct cancellation of repeat:
<1> fires
Entering ScaleIncrement: initial
SETting the value: 1.0
Rescheduling
end of <1>
Doit: arg is 1
Doit: Done 1
Cancelling
fvogel added on 2014-11-07 23:01:18: This statement of mine is wrong: However when the callback duration is much (e.g. 5 times) longer than -repeatdelay there is no problem. Did I already mention I'm lost :-) ? fvogel added on 2014-11-07 22:55:02: Clicking in the trough fires <1> event: - the new scale value is set in tk::ScaleIncrement - then a new execution of tk::ScaleIncrement is scheduled after -repeatdelay the first time, or after -repeatinterval next times Then, because the scale value is changed the callback gets launched. In the reported case it happens to last a bit longer than -repeatdelay. <ButtonRelease-1>, which cancels the repeat, does never fire before the callback execution is finished. At this point it becomes fishy: 1. When -repeatdelay is close to the callback duration, the issue arises: sometimes <ButtonRelease-1> fires just on time to cancel the repeat, sometimes it fires later (for instance because the focus has to be set on the toplevel first for instance) and cancels the second or even a later re-scheduling of tk::ScaleIncrement. 2. However when the callback duration is much (e.g. 5 times) longer than -repeatdelay there is no problem. I first thought that when callback execution is finished, tk::ScaleIncrement is run because the event loop determined that the elapsed time since scheduling is long enough. But observation 2. above is not compatible with that hypothesis. I have to admit I'm a bit lost but pretty much convinced there is an issue in event queueing / the way all these events fire in turn. Basically I would expect <ButtonRelease-1> to always fire right after callback execution is finished (this happens with 2. above but not with 1.), or even right after <1> has fired (never happens). I'm not proficient enough to fix this, I'm afraid. fvogel added on 2014-10-30 22:45:54: I see the scale advance 3 or even 4 steps when clicking once. I have also observed that: . problem always triggers when clicking on the through when wish does not have the focus . if wish already has the focus when clicking on the scale, then the issue is much harder to trigger . increasing -repeatdelay of the scale just above the duration of the callback makes the problem vanish (i.e. with the default -repeatdelay 300, .s conf -repeatdelay 345 is a problem but .s conf -repeatdelay 355 fixes it) What puzzles me is: . the (default) value for -repeatdelay is 300 ms . I click once as fast as I can: button up->down->up lasts certainly less than 1/3 of a second . nevertheless problem shows up Isn't this really a bug in the code (not in the doc)? It looks like the click duration measured by Tk includes something more than just how long the mouse button is down. How come that the execution time of the callback matters? dgp added on 2001-04-11 22:02:14: File Added - 5218: slider.tcl | |||
Attachments:
- slider.tcl [download] added by dgp on 2001-04-11 22:02:13. [details]
