Tk Source Code

View Ticket
Login
Ticket UUID: 1c9965ca71cd7b4b0bb3366b7b335466c466a7d8
Title: possible code issue: return before END_DRAWING
Type: Patch Version: core-9-0-branch, 8.6.18, 9.0.5, 9.1.0
Submitter: chrstphrchvz Created on: 2025-08-18 18:19:33
Subsystem: 88. Themed Tk Assigned To: marc_culler
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-09 02:39:44
Resolution: Accepted Closed By: chrstphrchvz
    Closed on: 2026-10-09 02:39:44
Description:

In EntryElementDraw() (near ttkMacOSXTheme.c:2126)

    if ([NSApp macOSVersion] > 100800) {
	BEGIN_DRAWING(d)
	    switch(kind) {
	    case kHIThemeFrameTextFieldRound:
		DrawEntry(dc.context, bounds, &searchDesign, state, tkwin);
		break;
	    case kHIThemeFrameTextFieldSquare:
		DrawEntry(dc.context, bounds, &entryDesign, state, tkwin);
		break;
	    default:
		return;
	    }
	END_DRAWING
    } else {

I am not aware of a trigger for this code path, but in the default case, is it a bug to return before END_DRAWING?

User Comments: chrstphrchvz added on 2026-10-09 02:39:44:

Thanks for getting this fixed. I neglected to comment here about the bug-1c9965ca-c86b and bug-1c9965ca-c90b branches I proposed. However I would still suggest for anyone interested in a ticket to have a look at its timeline view (with "info" in the URL, as opposed to the non-timeline view with "tktview" in the URL) for a better idea of any related activity.


marc_culler (claiming to be Marc Culler) added on 2026-10-01 17:39:57:
I have merged this patch into core-9-1-branch, core-9-0-branch and
core-8-6-branch.  So I am closing the ticket.

Thanks Serhiy!

marc_culler (claiming to be Marc Culler) added on 2026-10-01 15:14:21:
I see that the failure of font-17.5 was addressed today in [bf9aef00].
So I will go ahead and merge this.

marc_culler (claiming to be Marc Culler) added on 2026-10-01 14:49:57:
Well, the CI run failed because tests font-17.5 and button-16.1 failed.
The failure of font-17.1 has been reported by Torsten Berg on the core list
and the failure of button-16.1 has apparently been addressed. I do not
see font-17.1 failing on my machine, which indicates to me that it is a
sporadic failure, probably caused by a race condition.  I am sure it is
not related to this patch.  So I think it is safe to merge this.

serhiy.storchaka added on 2026-10-01 03:43:02:

button-16.1 is the test for [1100518], not related to this patch. On Aqua pressing a button does not change its relief (the pressed state is drawn natively), but the test expected "sunken". Fixed in [810f018b3d] (main), [bc39b6753a] (9.0) and [a1edb3c002] (8.6).


marc_culler (claiming to be Marc Culler) added on 2026-09-30 23:14:36:
I have to correct my statement that I saw no unexpected test errors.
There was one which I have not seen before:

==== button-16.1 button keeps -overrelief after click, Bug 1100518 FAILED
==== button-16.1 FAILED

I doubt that this patch could affect button tests.

Does anyone know anything about that failure?

marc_culler (claiming to be Marc Culler) added on 2026-09-30 20:54:23:
This looks correct.  I guess the CI will run tonight.  Assuming the CI run
is OK (which it should be - I saw no unexpected test failures on my machine),
I think this can be merged.

serhiy.storchaka added on 2026-09-30 15:06:39:

Both are bugs: TkMacOSXRestoreDrawingContext() pops the graphics state pushed by TkMacOSXSetupDrawingContext(), releases the clip region and schedules the update of the view, so returning without it leaves an extra saved graphics state, leaks the clip region and misses the update.

A search for other returns between a successful TkMacOSXSetupDrawingContext() and TkMacOSXRestoreDrawingContext() found one more: XCopyArea() (tkMacOSXImage.c) returns BadDrawable without restoring the context if it has no CGContext.

Proposed fix in branch macos-restore-drawing-context: break instead of return in EntryElementDraw(), and restoring the context before returning in TkpDrawAngledCharsInContext() and XCopyArea(). Not tested on macOS.


nab added on 2025-09-05 11:34:34:
Hi,
would it be possible to go a little bit further with those findings?

best regards,
nicolas

chrstphrchvz added on 2025-08-23 01:19:46:

Spotted another likely instance of this issue in TkpDrawAngledCharsInContext() (tkMacOSXFont.c:1340):

    if (…
	    || !TkMacOSXSetupDrawingContext(drawable, gc, &drawingContext)) {
	return;
    }
    string = [[TKNSString alloc] initWithTclUtfBytes:source length:numBytes];
    if (!string) {
	return;
    }


marc_culler (claiming to be Marc Culler) added on 2025-08-19 17:49:13:
That looks like a bug to me.