Tk Source Code

View Ticket
Login
2026-10-09
02:39 • Ticket [1c9965ca] possible code issue: return before END_DRAWING status still Closed with 5 other changes artifact: f92b62b0 user: chrstphrchvz
2026-10-01
17:39 • Closed ticket [1c9965ca]. artifact: 4e8d7ba5 user: marc_culler
17:29
Backport fix for [1c9965ca71]: possible code issue: return before END_DRAWING check-in: 26d7a954 user: culler tags: core-8-6-branch
15:28
Backport fix for [1c9965ca71]: possible code issue: return before END_DRAWING check-in: d0a3c917 user: culler tags: core-9-0-branch
15:22
Merge macosx-restore-drawing-context - fixes [1c9965ca71]: possible code issue: return before END_DRAWING check-in: 89acf2ba user: culler tags: trunk, main
15:14 • Ticket [1c9965ca] possible code issue: return before END_DRAWING status still Open with 4 other changes artifact: fc2553d7 user: marc_culler
14:49 • Ticket [1c9965ca]: 4 changes artifact: 56cd0d8a user: marc_culler
03:43 • Ticket [1c9965ca]: 3 changes artifact: eee77f79 user: serhiy.storchaka
2026-09-30
23:14 • Ticket [1c9965ca]: 4 changes artifact: 9006ca3f user: marc_culler
20:54 • Ticket [1c9965ca]: 4 changes artifact: 640dba1c user: marc_culler
15:06 • Ticket [1c9965ca]: 4 changes artifact: 23a9b6e8 user: serhiy.storchaka
15:04
Fix [1c9965ca71]: possible code issue: return before END_DRAWING. Restore the drawing context on early returns after it was set up: in EntryElementDraw() for an unknown frame kind, in TkpDrawAngledCharsInContext() if the string cannot be created, and in XCopyArea() if there is no context. closed check-in: bc510f94 user: serhiy.storchaka tags: macos-restore-drawing-context
2025-09-19
21:08
Additional fix for [1c9965ca]: Aqua: return before END_DRAWING (edit: closed in favor of macos-restore-drawing-context branch) closed check-in: 3e82a60b user: chrstphrchvz tags: bug-1c9965ca-c90b
20:57
Fix [1c9965ca]: Aqua: return before TkMacOSXRestoreDrawingContext (edit: closed in favor of macos-restore-drawing-context branch) closed check-in: 9bb26ab0 user: chrstphrchvz tags: bug-1c9965ca-c86b
2025-09-05
11:34 • Ticket [1c9965ca] possible code issue: return before END_DRAWING status still Open with 3 other changes artifact: c7882b6f user: nab
2025-08-23
01:19 • Ticket [1c9965ca]: 4 changes artifact: a1018d66 user: chrstphrchvz
2025-08-19
17:49 • Ticket [1c9965ca]: 4 changes artifact: 30cee7e7 user: marc_culler
2025-08-18
18:19 • New ticket [1c9965ca]. artifact: f4495a86 user: chrstphrchvz

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.