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

Bug 358315

Summary: [Forms] Graphics disposed in form editor due to redraw of disabled image
Product: [Eclipse Project] Platform Reporter: Thomas Ehrnhoefer <thomas.ehrnhoefer>
Component: User AssistanceAssignee: Chris Goldthorpe <cgold>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cgold, remy.suen, robert.munteanu, shawn.minto, steffen.pingel, thomas.ehrnhoefer, tomasz.zarna
Version: 3.7   
Target Milestone: 3.8 M3   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 358647    
Attachments:
Description Flags
Patch to create test case
none
Fix version 1 none

Description Thomas Ehrnhoefer CLA 2011-09-20 18:21:19 EDT
It appears that since 3.7 Forms is disposing of an image it later tries to repaint.
We have a special task editor with an image appearing on-hover. If one hovers once, then submits the editor, immediatelya graphic is disposed exception is thrown. Further investigation showed that the disabled image is getting disposed, but something is triggering a repaint afterwards not checking for disposed widgets.
Comment 1 Thomas Ehrnhoefer CLA 2011-09-20 18:22:05 EDT
stacktrace:

org.eclipse.swt.SWTException: Graphic is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.SWT.error(SWT.java:4168)
	at org.eclipse.swt.graphics.Image.getBounds(Image.java:1164)
	at org.eclipse.ui.forms.widgets.ImageHyperlink.paintHyperlink(ImageHyperlink.java:108)
	at org.eclipse.ui.forms.widgets.ImageHyperlink.paintHyperlink(ImageHyperlink.java:93)
	at org.eclipse.ui.forms.widgets.AbstractHyperlink.paint(AbstractHyperlink.java:296)
	at org.eclipse.ui.forms.widgets.AbstractHyperlink$2.paintControl(AbstractHyperlink.java:84)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:229)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1564)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4585)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4985)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2530)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3752)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Comment 2 Shawn Minto CLA 2011-09-20 18:27:57 EDT
See ImageHyperlink line 82 where it disposes teh disabledImage but never sets it to null.  I am unsure why paint is being called after the dispose occurs.
Comment 3 Chris Goldthorpe CLA 2011-09-21 16:05:22 EDT
Do you have steps to reproduce the problem?
Comment 4 Shawn Minto CLA 2011-09-21 16:13:46 EDT
I don't have anything to show it off in as it is a custom Mylyn task editor page where this is reproducable.  The basic order of actions goes as follows though:

* Create an ImageHyperlink on a form page
* set the image on the link (which creates the disabled image in the ImageHyperlinkClass)
* set the image on the link to null
* set the ImageHyperlink to be disabled (i.e. setEnabled(false) )
* create a button that disposes all controls and redraws them in the same form page

If you open the form page and click the button, you should see the error right away.
Comment 5 Chris Goldthorpe CLA 2011-09-21 19:50:19 EDT
Created attachment 203806 [details]
Patch to create test case

I have been able to reproduce by applying the attached patch to org.eclipse.ui.forms.examples.

It seems that these two lines were the only ones required.

  ih.setImage(null);
  ih.setEnabled(false);

There was no need to dispose any controls.
Comment 6 Chris Goldthorpe CLA 2011-09-21 20:12:25 EDT
Created attachment 203807 [details]
Fix version 1

This patch fixes the Graphic is disposed exception for my test case. I'm pretty sure that it will fix the problem you were seeing. Do you want to test the fix before I commit the change?
Comment 7 Steffen Pingel CLA 2011-09-22 04:14:33 EDT
*** Bug 333329 has been marked as a duplicate of this bug. ***
Comment 8 Steffen Pingel CLA 2011-09-22 04:19:02 EDT
Thanks for fixing this! Any change this change could make it into 3.7.2?
Comment 9 Shawn Minto CLA 2011-09-22 11:17:15 EDT
This looks like the correct fix to me Chris!  Thanks for the quick response on this.
Comment 10 Chris Goldthorpe CLA 2011-09-22 14:40:46 EDT
Patch applied to R3_development and R4_development streams. This is now fixed for Eclipse 3.8 and 4.2

I agree that the fix should go into 3.7.2 - I will clone this bug to track the backport. Once this is in a build can someone verify that it fixes the original problem?
Comment 11 Tomasz Zarna CLA 2011-10-27 06:58:16 EDT
*** Bug 314484 has been marked as a duplicate of this bug. ***