简体   繁体   English

调试窗口小部件被处置异常

[英]Debugging a `Widget is disposed` exception

A widget is disposed exception get thrown in our application and I'm struggling to find widget is causing the problem. 一个小部件被处置异常被抛出到我们的应用程序中,我正在努力寻找导致该问题的小部件。

It is an RCP 4 application with multiple perspectives and views. 它是一个具有多个视角和视图的RCP 4应用程序。 When the exception occurs the stack trace shows the last piece of code to be called but doesn't tell us which widget has been disposed of. 发生异常时,堆栈跟踪会显示要调用的最后一段代码,但不会告诉我们已丢弃了哪个小部件。

I've tried putting breakpoints on the dispose method of Widget but there are so many widgets getting disposed that it is prohibitive. 我尝试过在Widgetdispose方法上设置断点,但是有太多的widget被丢弃,这是禁止的。

!ENTRY org.eclipse.e4.ui.workbench 4 0 2019-04-26 10:14:00.114
!MESSAGE Internal Error
!STACK 0
org.eclipse.swt.SWTException: Widget is disposed
    at org.eclipse.swt.SWT.error(SWT.java:4595)
    at org.eclipse.swt.SWT.error(SWT.java:4510)
    at org.eclipse.swt.SWT.error(SWT.java:4481)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:451)
    at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:350)
    at org.eclipse.swt.widgets.Control.computeSize(Control.java:663)
    at org.eclipse.swt.custom.ScrolledCompositeLayout.computeSize(ScrolledCompositeLayout.java:36)
    at org.eclipse.swt.widgets.Composite.computeSizeInPixels(Composite.java:218)
    at org.eclipse.swt.widgets.Control.computeSize(Control.java:666)
    at org.eclipse.swt.layout.GridData.computeSize(GridData.java:494)
    at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:224)
    at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:200)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1362)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1369)
    at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1347)
    at org.eclipse.swt.widgets.Composite.setLayoutDeferred(Composite.java:1148)
    at org.eclipse.swt.widgets.Display.runDeferredLayouts(Display.java:3968)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3540)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1173)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1062)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:166)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:595)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1501)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1474)

What is the best method for finding the cause of a widget is disposed exception? 查找小部件被处置异常的最佳方法是什么?

This turned out to be to do with the ScrolledComposite as @greg-449 mentioned. 事实证明这与@ greg-449中提到的ScrolledComposite I missed it when first looking. 我第一次看时就错过了。

We used the parent composite to create the ScrolledComposite and then set the content. 我们使用父组合创建了ScrolledComposite ,然后设置了内容。 The content was being disposed but the reference was still stored causing the widget is disposed exception. 内容已被处置,但引用仍被存储,导致微widget is disposed异常。

final ScrolledComposite scroll = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.BORDER);
scroll.setContent(widgetThatIsDisposedLater);

To fix this I disposed the ScrolledComposite which meant that it would no longer try using its disposed content. 为了解决这个问题,我处理了ScrolledComposite ,这意味着它将不再尝试使用其处理的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM