| Ticket UUID: | 6051a9fca29285ce0b545c61413a713eeda33e01 | |||
| Title: | On windows, arcs with small 'extent' can be drawn incorrectly | |||
| Type: | Bug | Version: | 9.0 | |
| Submitter: | anonymous | Created on: | 2025-10-13 01:03:02 | |
| Subsystem: | 05. Canvas Items | Assigned To: | oehhar | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2025-11-03 17:06:29 | |
| Resolution: | Fixed | Closed By: | oehhar | |
| Closed on: | 2025-11-03 17:06:29 | |||
| Description: |
Hi, On windows, 'arc' canvas items with small -extent value, which should appear as a tiny sliver of a pie slice, are sometimes drawn as an entire pie - wrapping around from very small to very big. Whether or not this happens seems to depend on the size of the arc item, the -start value, and the -extent value itself. Here is a Tcl script that demonstrates the problem:
In order to reproduce the problem, run this script on Unix (x11), and run it on Windows. Observe that on Unix/x11, the 'arc' appears as a tiny sliver, so small that it looks just like a line segment. Observe that on Windows, the arc appears as a full circle with a line through it, and when you hover the mouse over the line, the small rectangular area containing the tiny sliver pie slice lights up white (the -activefill colour) and the rest of the circle does not light up. The highlighting behaviour when hovering the mouse over the area that is supposed to be filled by the arc, reveals that the drawing behaviour is incorrect - the 'collision detection' code clearly believes that the arc is a tiny sliver and not a whole pie. Regards, dhr | |||
| User Comments: |
oehhar added on 2025-11-03 17:06:29:
Merged revised version:
Thanks Christopher and eternal Francois for the fix ! Harald oehhar added on 2025-10-31 13:14:52: I have verified the widget demo issue for ovals, which is critical. Ovals are drawn highly obscured. The comparison picture is attachement [widget_demo_canvas_items_ovals_patch-artefact_no-patch.png]. I can say, that the oval artefacts are gone with the patch by Christopher. Great work, I appreciate ! So I would be in favor to merge the branch now. If there is no objection, I will do so next Monday. Thanks for all, Harald jan.nijtmans added on 2025-10-31 10:46:59: It would be nice if this fix appears in Tk 9.0.3. Release cycle will start soon ..... chrstphrchvz added on 2025-10-30 14:28:14: Please have a look at [a89a807d], which is another attempted fix for both this ticket and the oval item regression. I do not mean to take credit for it though, as I have peeked at the source for the actual X11 server arc fill routines: https://github.com/XQuartz/xorg-server/blob/0ea9b59/mi/mifillarc.c#L678. These clamp the extent to ±360 degrees, which makes sense since it is historically constrained to the signed 16-bit range which itself is not much larger than [-64*360,64*360]. oehhar added on 2025-10-26 09:54:55: Thanks. It is better to know bad knews. Backed out by:
Thanks, Harald chrstphrchvz added on 2025-10-25 20:37:06: Unfortunately the change for this issue has introduced a regression where oval items no longer draw properly (see e.g. canvas items widget demo) and might need to be backed out for now. Sorry for the inconvenience. oehhar added on 2025-10-21 08:05:42: Fix merged to all branches:
Thanks for Christopher and Francois for the bugfix, highly appreciated. All but one bugfix for Tk in upcoming Tk 8.6 release are from Christopher. Thanks for the action ! Closing. Take care, Harald oehhar added on 2025-10-21 07:48:16: I have made a local test. The test does not fail for me. So, it is probably a timeout issue. I will merge now. Thanks for all, Harald oehhar added on 2025-10-21 07:25:47: There is one canvas test with images failing: https://github.com/tcltk/tk/actions/runs/18675528966/job/53244610140#step:9:310 I will try to run manually. Thanks, Harald oehhar added on 2025-10-20 16:53:29: Ok. CI scheduled. Will merge when result is positive. I don't think there is any issue which might be detected by CI but anyway. Thanks, Harald chrstphrchvz added on 2025-10-20 16:43:02: Yes, I think this is ready to merge. Thanks again oehhar added on 2025-10-20 15:38:12: Christopher, looks good to me, thanks. Test it, works great. For me, it may be merged to main, core-9-0 and core-8-6. Shall I do that? Thanks, Harald oehhar added on 2025-10-20 15:34:48: The recipe does not work. You need a tcl9.1, as this is tk9.1 now. Best would be to use a tcl from the main branch. The naming of the folders should be tcl9.1 and tk9.1. This allows to avoid the specification of TCLDIR=c:\test\... when building tk. But it does not hurt. Sorry, Harald oehhar added on 2025-10-20 15:08:49: One error: cd c:\test\tk9.0.2\tk -> cd c:\test\tk9.0.2\win oehhar added on 2025-10-20 15:06:40: @ drh:
Good luck, Harald anonymous (claiming to be dhr) added on 2025-10-20 14:39:10: Hi Harald, > @dhr, are you able to test and confirm, that the patch is effective for you? I would be happy to test it and confirm, but I don't know how to obtain the patched source/branch, and I don't know how to build Tcl/Tk from source on windows. If there is a guide somewhere that explains what to do, let me know and I'll look into building and testing it, otherwise it's probably not worth your time/effort to teach me how to build Tcl/Tk on windows. Sorry for the trouble. Thanks a lot Christopher and Harald for the work in investigating this issue. Regards, dhr chrstphrchvz added on 2025-10-18 21:50:49: For testing the near-360 degree behavior, I used the reporter's animated example with -extent 359.8. The animation should show a complete or almost-complete filled circle and not "flicker". François' approach is closer to the desired behavior, where arcs with an extent near 0 degrees still draw something (a point or line), rather than draw nothing as my approach does. Although his approach has the same issue as my first approach where an extent just under 360 degrees may get treated as 0 degrees and not draw as expected, I think that is easy to fix. So for now I would propose François' approach combined with an adjustment to handle near-360 degree arcs properly; see [06a80feb]. Regarding the other issues in [1081603], I do not know whether it is worth trying to get the arc drawing on Windows to match X11 exactly. Maybe such microscopic differences should be accepted as a limitation of the Win32 Tk port or the GDI functions it relies on. chrstphrchvz added on 2025-10-17 23:23:35: I meant to check whether this issue is a duplicate, particularly given how long it has existed; apologies for not doing so earlier. This appears to be the same issue described in the comment dated 2007-09-26 on [1081603], and for which François proposed a fix 8 years ago in [ed8e17cc]. I would want to look at his approach before proceeding. oehhar added on 2025-10-16 08:11:21: Christopher, thanks, great, I appreciate ! I would love some additional source code commenting, why we need this flag. I can do that, if you like. Is there an example to test the "rounded 360°" case ? Perhaps, test wizard Eric may comment on the test possibility. Sad, thant magic Francois is not here any more, we miss his detailed work. @dhr, are you able to test and confirm, that the patch is effective for you? I am in favor (as TCT member) to merge to main, core-9-branch and core-8-6-branch. IMHO, the patch is an improvement, what is great. If Christover is also in favor, it may be merged. Thanks for all, Harald chrstphrchvz added on 2025-10-15 19:41:24: Harald, thanks for the review and creating the branch. Maybe an interactive test is possible for this issue, although I am not familiar with those. As documented, the canvas arc items treat an extent of 360 degrees or more as the extent modulo 360 degrees, so it is not possible to specify 360 degrees exactly. However it is still possible to specify an amount like 359.8 degrees which may get rounded to 360 degrees by DrawOrFillArc(), so I have pushed a revised fix [32db5e81] which accounts for that. oehhar added on 2025-10-15 08:47:16: Christopher, thanks for the fix. It is now in commit [2c3275d0] starting branch [6051a9fc-win-arc-small]. For me, it is effective. Now, only a line is drawn for both examples (MS-Win 11 64bit, MS-VS2022 64 bit). I have two questions:
Thanks for all, Harald chrstphrchvz added on 2025-10-14 21:09:37: A note for the reporter: consider using [tk windowingsystem] to check for X11/Win32/Aqua rather than $tcl_platform(os). In DrawOrFillArc() (tkWinDraw.c), input angles are converted to radials. After rounding, it is possible for these radials to be identical, i.e. xstart == xend and ystart == yend. The problem is that passing identical radials to the Win32 GDI functions Arc(), Chord(), and Pie() causes them to draw 360 degrees, rather than 0 degrees as Tk seems to expect. Note: only the rectangular portion within the bounding box of an arc item is visible, and not necessarily all of the 360 degrees of drawing. A naïve solution might be something like this, although I am not certain it is correct for XFillArc() usage other than canvas arc items: --- win/tkWinDraw.c +++ win/tkWinDraw.c @@ -1261,7 +1261,9 @@ oehhar added on 2025-10-14 07:21:52: Thanks for the report. I can confirm, that the bug is in Tk 8.6.16 and Tk 9.0.2. Attached is a screenshot of the first example, as the 2nd example is animated and hard to make a screen shot. For me, it is also clear, that we need an antialiased version, as this looks outdated. I also tested with undroidwish. It does not have the bug (see attached). For those who want to understand the issue, please compare the undrowish and the windows screenshot. anonymous added on 2025-10-13 21:18:34: Here's another test script that might demonstrate the problem a bit more clearly:
I've also attached a screenshot of this test script running on Tcl/Tk 9.0 for windows (via wine, but the behaviour was identical on my friend's computer with windows 11), Tcl/Tk 8.6.12 on Linux, and a historical version of Tcl/Tk for comparison. It seems like the windows version of Tk has had this bug since at least late 1996. | |||
Attachments:
- widget_demo_canvas_items_ovals_patch-artefact_no-patch.png [download] added by oehhar on 2025-10-31 13:07:10. [details]
- example_1_win11_64bit_undroidwish.png [download] added by oehhar on 2025-10-14 07:22:20. [details]
- example_1_win11_64bit_tk9.0.2.png [download] added by oehhar on 2025-10-14 07:10:56. [details]
- screenshot_Mon13Oct2025__22_04_34.png [download] added by anonymous on 2025-10-13 21:14:05. [details]
