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

Bug 142582

Summary: [OLE] "widget is disposed" after reparenting OleControlSite
Product: [Eclipse Project] Platform Reporter: Bob Pleva <buggyreport>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Felipe Heidrich <eclipse.felipe>
Severity: normal    
Priority: P3 CC: andrew, snorthov, veronika_irvine
Version: 3.2Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug
Attachments:
Description Flags
TestCase that fails.
none
TestCase that fails. none

Description Bob Pleva CLA 2006-05-18 14:59:59 EDT
After I'm done with an OleControlSite, I setParent() to a "non visisble holding composite", and then I dispose() its parent, which is an OleFrame.  The next time I need an OleControlSite, I take a previous one, create a new OleFrame, and then set the parent to the new OleFrame.  That works on the UI.. until a focusIn event is received by OleControlSite.  COMObject seems to look up the old (original) OleFrame and sends it setMenu().  That results in the "widget is disposed" error.   In case you're wondering why I'm attemting to re-use OleControlSites, it's because we instantiate and dispose tons of them in our app, and there is a very significant handle / memory leak because of that.

Stack Trace:
org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3374)
	at org.eclipse.swt.SWT.error(SWT.java:3297)
	at org.eclipse.swt.SWT.error(SWT.java:3268)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:432)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:327)
	at org.eclipse.swt.widgets.Control.getShell(Control.java:1101)
	at org.eclipse.swt.ole.win32.OleFrame.SetMenu(OleFrame.java:695)
	at org.eclipse.swt.ole.win32.OleFrame.access$9(OleFrame.java:690)
	at org.eclipse.swt.ole.win32.OleFrame$5.method10(OleFrame.java:300)
	at org.eclipse.swt.internal.ole.win32.COMObject.callback10(COMObject.java:153)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1922)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
	at ReParentOleBrowser.run(ReParentOleBrowser.java:175)
	at ReParentOleBrowser.main(ReParentOleBrowser.java:50)

I have a sample program if you need it.

I'm using the latest SWT I could find..  swt-win32-3230.dll with a corresponding swt.jar file.
Comment 1 Bob Pleva CLA 2006-05-18 15:06:17 EDT
Created attachment 41925 [details]
TestCase that fails.

Here is a small test case showing the problem.
Comment 2 Bob Pleva CLA 2006-05-18 15:06:25 EDT
Created attachment 41926 [details]
TestCase that fails.

Here is a small test case showing the problem.
Comment 3 Grant Gayed CLA 2006-05-29 15:04:06 EDT
- I see a Widget is Disposed exception when closing the example after opening/closing 1+ browsers
- the exception I see has a different trace than the one in comment 0, but is still Widget is Disposed
- the presence/absence of Sleak is not relevant to the problem
Comment 4 Andrew Bromley CLA 2009-07-01 13:48:16 EDT
I have a similar problem as described below. The added complication of dual bridging is probably not relevant. It does however appear that removal of the ole container from a parent container is the cause of the problem.

Problems with SWT AWT Bridge

I am trying to embed a windows mediaplayer object in a java application, using the SWT-AWT Bridge,
within a swing application which is wrapped by an SWT Frame. This is because the application
is also used as an applet. The system uses JAVA 1,5 compatability, a requirement for use on a MAC.
The media player wrapper is held in a panel which due to view requirements is moved between parent containers.
Note the embedded SWT for the media player uses the dispatch loop of the applications frame. A minor problem is getting tyh media player to size to its containing panel, but a resize of the
application achieves this. The major problem is that when the containing panel is removed from a parent 
container, the mutimedia object is disposed of. Creating a new instance is carried out, but now a resize
of the application causes an exception listed beow :-

Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:194)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4251)
	at org.eclipse.swt.awt.SWT_AWT$11.componentResized(SWT_AWT.java:374)
	at java.awt.AWTEventMulticaster.componentResized(Unknown Source)
	at java.awt.Component.processComponentEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.SWT.error(SWT.java:3666)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336)
	at org.eclipse.swt.widgets.Control.setSize(Control.java:3100)
	at org.eclipse.swt.awt.SWT_AWT$12.run(SWT_AWT.java:377)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800)
	at org.eclipse.swt.widgets.Display.msgFilterProc(Display.java:3166)
	at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
	at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
	at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
	at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2371)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at com.cadking.vc.ui.rcp.dataentry.Application.start(Application.java:360)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
	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:386)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:194)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4251)
	at org.eclipse.swt.awt.SWT_AWT$11.componentResized(SWT_AWT.java:374)
	at java.awt.AWTEventMulticaster.componentResized(Unknown Source)
	at java.awt.Component.processComponentEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.SWT.error(SWT.java:3666)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336)
	at org.eclipse.swt.widgets.Control.setSize(Control.java:3100)
	at org.eclipse.swt.awt.SWT_AWT$12.run(SWT_AWT.java:377)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3425)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at com.cadking.vc.ui.rcp.dataentry.Application.start(Application.java:360)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
	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:386)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1212)

The disposed widget appears to be the display object of the shell for the media player. However program tracing
showd that it is NOT disposed either side of the create shell invocation. The media player stays running,
as does the embedded swing stuff, but the SWT frame ceases to respond, can't be resized, or closed.

Note the mediaplayer can be disposed of and recreated to play media without problems other than initial size,
and the application resized without problems in one of the views. Also I have tried running a dispose of the
media player via synExec() before its containing panel is removed from its parent, but this does not prevent
the exceptions.

The exception allows occurs after the containing panel has had the mediaplayer object created, been removed from
its containing panel, reinserted into the panel and a new mediaplayer object creted, and the application resized.
It does not matter whether or not the application is resized for the first created media player. Also media players
can be disposed of, and new ones created and resized without problems so long as the containing panel remains in
its parent. Once a media player has been created, disposing of it before the containing panel is removed from
its container does not affect the problem. Removal of the containing panel from its parent causes it to be
disposed if not previously disposed of. A new media player can be created in the panel, and starts playing the media
, its is when the application resizes that the failure occurs.

This appears to be the same as bug 142582.

This may help :-)

Andrew
Comment 5 Andrew Bromley CLA 2009-07-02 05:15:04 EDT
Just to clarify my previous posting, the problem occurs for a newly created olecontrol after the container panel has had a control created for it, regardless of whether this is disposed of before it is removed from its parent. Removal of the container panel from its parent triggers the bug. This also the disposal of the control container if it left alone before this event. I would not expect this as this can be part of user interface re-organization, with the container panel replacing an split pane control for example,  where i would expect the control be be in an unchanged state.

Also, where a card layout manager is used to switch displayed panels, the control container can be switched in and out without causing the bug.

I hope this points someone in the right direction,

Andrew.
Comment 6 Felipe Heidrich CLA 2009-08-13 10:28:12 EDT
Your bug has been moved to triage, visit http://www.eclipse.org/swt/triage.php for more info.
Comment 7 Leo Ufimtsev CLA 2017-08-03 12:26:38 EDT
This is a one-off bulk update. (The last one in the triage migration).

Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process:
https://wiki.eclipse.org/SWT/Devel/Triage

See Bug 518478 for details.

Tag for notification/mail filters:
@TriageBulkUpdate
Comment 8 Eclipse Genie CLA 2020-03-07 17:36:25 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.