Skip to content

Commit 0ddbf9f

Browse files
committed
Do not set IME font if the font is disposed
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
1 parent 13934ee commit 0ddbf9f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public static long getFontHandle(Font font, int zoom) {
7474
if (font == null) {
7575
SWT.error(SWT.ERROR_NULL_ARGUMENT);
7676
}
77+
if(font.isDisposed())
78+
{
79+
return 0;
80+
}
7781
return Font.win32_getHandle(getFont(font.getDevice(), font.getFontData()[0], zoom));
7882
}
7983

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Canvas.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
108108
font.dispose();
109109
}
110110

111+
@Test
112+
public void test_CaretWithDisposedFontDoesNotThrowException_issue2323() {
113+
try {
114+
Caret caret = new Caret(canvas, SWT.NONE);
115+
Font font = new Font(canvas.getDisplay(), "Default", 10, SWT.BOLD);
116+
shell.open();
117+
caret.setFont(font);
118+
font.dispose();
119+
canvas.setFocus();
120+
canvas.setCaret(caret);
121+
} catch (Exception e) {
122+
fail("Exception thrown when a canvas sets a caret with a disposed font: " + e.getMessage());
123+
}
124+
}
125+
111126
/* custom*/
112127
@Test
113128
public void test_consistency_MenuDetect() {

0 commit comments

Comments
 (0)