Community
Participate
Working Groups
Version: CVS HEAD Steps to reproduce: 1. Set the font on the GC to a non-factory created font (i.e., user instantiated) 2. Draw text on the GC. 3. Dispose of the font. If the dispose() call on the Font occurs before renderChanges() is called in the CanvasLCA an exception is thrown: org.eclipse.swt.SWTException: Graphic is disposed at org.eclipse.swt.SWT.error(SWT.java:3190) at org.eclipse.swt.SWT.error(SWT.java:3110) at org.eclipse.swt.SWT.error(SWT.java:3081) at org.eclipse.swt.graphics.Font.getFontData(Font.java:177) at org.eclipse.swt.internal.widgets.canvaskit.GCOperationWriter.toCSSFont(GCOperationWriter.java:235) at org.eclipse.swt.internal.widgets.canvaskit.GCOperationWriter.setFont(GCOperationWriter.java:229) at org.eclipse.swt.internal.widgets.canvaskit.GCOperationWriter.write(GCOperationWriter.java:57) at org.eclipse.swt.internal.widgets.canvaskit.CanvasLCA.writeGCOperations(CanvasLCA.java:62) at org.eclipse.swt.internal.widgets.canvaskit.CanvasLCA.renderChanges(CanvasLCA.java:46) This is a common use-case since the graphics operations are actually processed/accomplished after the code that called them is finished. So the user-code actually is a good citizen by disposing the fonts as soon as they are not needed, and is unaware that the GC operations will need the "undisposed" font later during renderChanges(). Potential Solutions: 1. Do not throw an exception in Font.getFontData() since in RAP it does not really care if the font is disposed or not in terms of obtaining FontData. 2. Make an undisposed copy of the Font objects that are set into the GCOperationWriter in renderChanges().
Created attachment 177039 [details] Patch for potential solution 1
(In reply to comment #0) > > 2. Make an undisposed copy of the Font objects that are set into the > GCOperationWriter in renderChanges(). In this case I am implying that there be some internal API that can obtain the font data without throwing an exception.
This is related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=321135
Fixed by creating an "internal" copy of the external font in GC#setFont(). Changes are in CVS HEAD.