Tk Source Code

View Ticket
Login
Ticket UUID: ec2dcb36ca9967e8940dc400d3e2a053c723e13a
Title: Tk 9.0.1 crash when resizing a window with a ttk::panedwidget containing a ttk::button on macOS 10.13
Type: Bug Version: 9.0.1
Submitter: EricBrunel Created on: 2025-03-05 15:56:03
Subsystem: 66. Aqua Window Operations Assigned To: marc_culler
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2025-03-08 16:42:14
Resolution: Fixed Closed By: marc_culler
    Closed on: 2025-03-08 16:42:14
Description:

With tcl/tk 9.0.1 built from the source code on macOS 10.13 with the patch correcting the build issue in ticket cb5d776b12, run the following script:

ttk::panedwindow .panes -orient horizontal
pack .panes -fill both -expand yes

ttk::frame .panes.left
.panes add .panes.left -weight 1
pack [ttk::button .panes.left.btn -text Action] -side top -fill x -padx 2 -pady 2

ttk::frame .panes.right
.panes add .panes.right -weight 1
pack [ttk::frame .panes.right.frm -width 300 -height 200]

Then resize the window from its right side until the button in the left pane disappears. This causes a crash with the message:

Assertion failed: (corner_width >= 0 && 2 * corner_width <= CGRectGetWidth(rect)), function CGPathCreateWithRoundedRect, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Quartz2D/Quartz2D-1161.21.5/CoreGraphics/Paths/CGPath.cc, line 188.
Abort trap: 6

This does not seem to happen on more recent versions of macOS: on a build with the same sources on macOS 13.2, the problem does not happen.

User Comments: marc_culler (claiming to be Marc Culler) added on 2025-03-08 16:42:14:
Hi Eric. Thanks for noticing that. I removed that redundant (and wrong)
code from DrawGrayButton.

EricBrunel added on 2025-03-08 08:29:30:

I did test on my iMac with macOS 10.13, and I confirm that everything works fine now.

Thanks a lot!

By the way, the radius set to -1 might require another little adjustment: in file ttkMacOSXTheme.c, function DrawGrayButton, there is what seems to be an attempt at correcting the radius, except that it's wrong - it considers only the button's height, and not its width - and it's now unneeded, since the CHECK_RADIUS macro is now called systematically and does the job. Just a tiny optimization.


marc_culler (claiming to be Marc Culler) added on 2025-03-08 03:10:37:
I checked this on a macOS 10.13 VM and it seemed fine.  I think that is
enough insurance to close the ticket.

marc_culler (claiming to be Marc Culler) added on 2025-03-07 14:46:41:
Eric,

Would you please test one more time, just to make sure?

Thanks.

marc_culler (claiming to be Marc Culler) added on 2025-03-07 14:27:10:
Hi Eric,

Thank you very much!

Most of the time the radius is provided by a ButtonDesign defined in
ttkMacOSXTheme.h and all of those set the radius to a non-negative
value.  I did find one place where the radius could get computed in
terms of the button height:

    CGFloat radius = 2 * design->radius <= bounds.size.height ?
        design->radius : bounds.size.height / 2;

I can only guess that some quirk of macOS 10.13 causes the button
height to be negative.

Question: When you say that the radius was -1 did you mean -1.0 (since
radius is a float) or did the radius somehow get cast to an int with
value -1?

Anyway, your suggestion looks good and I will add it to the bugfix
branch.

EricBrunel added on 2025-03-07 09:04:14:

Thanks for looking into it, Marc. Unfortunately, I tested the code on the branch, and I'm still getting a crash.

I did a few tests and I narrowed it down to the call to FillRoundedRectangle in DrawGrayButton in ttkMacOSXTheme.c: it seems that in my case, the corner radius passed to FillRoundedRectangle ends up being -1, which is a case that the macro CHECK_RADIUS doesn't test. If I change the condition in the if in the macro definition to:

radius < 0 || 2 * radius > bounds.size.width || 2 * radius > bounds.size.height

I don't get a crash anymore.

Thanks again!


marc_culler (claiming to be Marc Culler) added on 2025-03-07 01:08:59:
Well, it turned out that there were several calls to CGPathCreateFromRoundedRect
which were not protected by checks that the corner radius was less than half
the side length.

I created a bugfix branch bug-ec2dcb36c which adds checks to all of those calls.

Eric, can you please test that branch on your High Sierra system?  (Not all
OS releases crash when that rule is broken.  Some just correct the radius.)

marc_culler (claiming to be Marc Culler) added on 2025-03-06 23:03:45:
That assertion is checking that there is a linear segment of positive
length on each side of the rounded rectangle.  In many cases we chack
for that and use a normal rectangle when the bounds are too small to
accomodate corners.  I thought we were doing that in all cases, but
apparently one was missed.  It would be nice to know that it is really
Tk that is generating this, rather than the HITheme library which is
used for drawing older versions of native widgets.  If you could generate
the crash after replacing Tk by Tk_debug and upload the crash report
I could probably find where the problem is.