Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351216

Summary: [GC] Throws unexpected "Graphic is diposed" exception
Product: [RT] RAP Reporter: Rüdiger Herrmann <ruediger.herrmann>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: a_mergey
Version: 1.3   
Target Milestone: 1.5 M1   
Hardware: All   
OS: All   
Whiteboard:

Description Rüdiger Herrmann CLA 2011-07-05 12:12:55 EDT
The snippet below works in SWT but fails in RWT:

canvas.addPaintListener(new PaintListener() {
		public void paintControl(PaintEvent event) {
			Rectangle rect = canvas.getClientArea();
			Color color = new Color( display, 0, 128, 64 );
			event.gc.setForeground( color );
			event.gc.drawOval(0, 0, rect.width - 1, rect.height - 1);
			color.dispose();
		}
	} );

The CanvasLCA accesses properties from the already disposed color object in order to assemble the changes to be sent to the client.
	
Stack trace
-------------
org.eclipse.swt.SWTException: Graphic is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3536)
	at org.eclipse.swt.SWT.error(SWT.java:3459)
	at org.eclipse.swt.SWT.error(SWT.java:3430)
	at org.eclipse.swt.graphics.Color.getRed(Color.java:175)
	at org.eclipse.rwt.lifecycle.JSWriter.getColorValue(JSWriter.java:902)
	at org.eclipse.rwt.lifecycle.JSWriter.createParamList(JSWriter.java:837)
	at org.eclipse.rwt.lifecycle.JSWriter.createParamList(JSWriter.java:805)
	at org.eclipse.rwt.lifecycle.JSWriter.call(JSWriter.java:595)
	at org.eclipse.swt.internal.widgets.canvaskit.GCOperationWriter.setProperty(GCOperationWriter.java:233)
	at org.eclipse.swt.internal.widgets.canvaskit.GCOperationWriter.write(GCOperationWriter.java:72)
	at org.eclipse.swt.internal.widgets.canvaskit.CanvasLCA.writeGCOperations(CanvasLCA.java:62)
	at org.eclipse.swt.internal.widgets.canvaskit.CanvasLCA.renderChanges(CanvasLCA.java:45)
	at org.eclipse.rwt.lifecycle.AbstractWidgetLCA.render(AbstractWidgetLCA.java:36)
	at org.eclipse.swt.internal.widgets.displaykit.DisplayLCA$RenderVisitor.render(DisplayLCA.java:73)
Comment 1 Rüdiger Herrmann CLA 2011-07-05 12:15:47 EDT
Other resources (Font, Image, what else?) are probably also affected.
Comment 2 Rüdiger Herrmann CLA 2011-07-05 14:18:41 EDT
The exception when using a Color during a GC operation and immediately disposing of it is fixed. Instead of storing the Color object for later rendering, only the RGB object that describes the color is stored.
Changes are in CVS HEAD (and will be in 1.5M1)

I will leave this bug open until potential issues with other Resources are fixed or it turns out that they are not affected.
Comment 3 Rüdiger Herrmann CLA 2011-07-05 14:35:59 EDT
Fonts are not affected, added test case to GCOperationWriter_Test to further ensure this. Changes are in CVS HEAD
Comment 4 Rüdiger Herrmann CLA 2011-07-05 14:55:40 EDT
I added a test to ensure that rendering a GC with disposed image does not cause exception.
As Cursor isn't used by GC methods, all Resources that can be used by a GC are now safe.