Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323183 - [GC] Font disposal breaks GC
Summary: [GC] Font disposal breaks GC
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.4 M2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-19 15:00 EDT by Austin Riddle CLA
Modified: 2010-08-23 04:19 EDT (History)
0 users

See Also:


Attachments
Patch for potential solution 1 (857 bytes, patch)
2010-08-19 15:03 EDT, Austin Riddle CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Austin Riddle CLA 2010-08-19 15:00:39 EDT
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().
Comment 1 Austin Riddle CLA 2010-08-19 15:03:41 EDT
Created attachment 177039 [details]
Patch for potential solution 1
Comment 2 Austin Riddle CLA 2010-08-19 15:06:47 EDT
(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.
Comment 3 Austin Riddle CLA 2010-08-19 15:08:10 EDT
This is related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=321135
Comment 4 Ivan Furnadjiev CLA 2010-08-23 04:19:40 EDT
Fixed by creating an "internal" copy of the external font in GC#setFont(). Changes are in CVS HEAD.