Skip to content

Conversation

@arunjose696
Copy link
Contributor

Prior to PR #2062, the hFont variable in Caret::setIMEFont was retrieved directly from the font object (using font.handle). Since #2602, hFont is fetched via SWTFontProvider, which throws an exception if the font is disposed.

Previously, when the font was disposed, hFont (font.handle) would be zero, and the method would fall back to using defaultFont for setting the IME font. After #2602, this fallback no longer works because the exception is thrown before the fallback can occur.

This commit restores the intended behavior by setting hfont as zero if the font is disposed, preventing the exception.

Fixes #2323

Steps to reproduce

Run the snippet provided in #2323 (comment).
Without this change, an exception will be thrown when the font is disposed.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2025

Test Results

   546 files  ± 0     546 suites  ±0   27m 9s ⏱️ -1s
 4 417 tests + 4   4 400 ✅ + 4   17 💤 ±0  0 ❌ ±0 
16 738 runs  +16  16 611 ✅ +16  127 💤 ±0  0 ❌ ±0 

Results for commit 1426edf. ± Comparison against base commit e8aadbb.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look sound and adhere to previous state. I have just one comment.

Comment on lines 513 to 514
{
hFont = font.isDisposed() ? 0 : SWTFontProvider.getFontHandle(font, getNativeZoom());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check for font being disposed inside of the SWTFontProvider.getFontHandle and return 0 if its disposed? Wouldn't that be safer for all the consumers?

Copy link
Contributor

@akoch-yatta akoch-yatta Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes, sounds good to me. That would solve this issue here as well and is equal to the original behavior: Is a font disposed return a 0 handle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@arunjose696 arunjose696 force-pushed the arunjose696/368/FontDisposalIMEFont branch from 053451d to 0ddbf9f Compare August 1, 2025 11:07
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Approved

…2323

Prior to recent changes that ensure that a font handle is always
retrieved via the SWTFontProvider, the hFont variable in
Caret::setIMEFont was retrieved directly from the font object (using
font.handle). Since those recent changes, hFont is fetched via
SWTFontProvider, which throws an exception if the font is disposed.

Previously, when the font was disposed, hFont (font.handle) would be
zero, and the method would fall back to using defaultFont for setting
the IME font. Now, this fallback no longer works because the exception
is thrown before the fallback can occur.

This commit restores the intended behavior by setting hFont as zero if
the font is disposed, preventing the exception.

Fixes eclipse-platform#2323
@HeikoKlare HeikoKlare force-pushed the arunjose696/368/FontDisposalIMEFont branch from 0ddbf9f to 1426edf Compare August 3, 2025 11:38
@HeikoKlare HeikoKlare changed the title Do not set IME font if the font is disposed [Win32] Do not set IME font if the font is disposed Aug 3, 2025
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is sound and fixes the reported issue.

I have adapted the PR with corrected formatting and slightly updated the commit message to fit to our recommendations.

@HeikoKlare HeikoKlare merged commit 7f19dc5 into eclipse-platform:master Aug 3, 2025
17 checks passed
@HeikoKlare HeikoKlare deleted the arunjose696/368/FontDisposalIMEFont branch August 3, 2025 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SWTException: Font with disposed graphics Assertion in Caret.setIMEFont

4 participants