org.eclipse.swt.SWTException: "Widget is disposed" from table refresh
Asked Answered
C

3

8

The app is an Eclipse 3.6 based RCP (so jface version 3.5.2) running on windows 7.

I have a custom View class that contains a TableViewer and calls refresh() on it. Sometimes, but not very often it results in the stack trace below. It's called from within the UI thread. I suspected the problem was with other code that changes the backing list to the table, but that any code that does this is also run in either a syncExec or asyncExec method so I don't understand how it could be a synchronisation issue between the changing of table items and the refresh of the viewer.

Any ideas what i can do to prevent this happening?

!ENTRY org.eclipse.jface 4 2 2010-10-20 09:22:06.140 !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jface". !STACK 0 org.eclipse.swt.SWTException: Widget is disposed 
at org.eclipse.swt.SWT.error(SWT.java:3884) at org.eclipse.swt.SWT.error(SWT.java:3799) 
at org.eclipse.swt.SWT.error(SWT.java:3770) 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.Widget.getData(Widget.java:521) 
at org.eclipse.jface.viewers.AbstractTableViewer.setSelectionToWidget(AbstractTableViewer.java:921) 
at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:1711) 
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1399) 
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1353) 
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1455) 
at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537) 
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1414)
... 
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
Culosio answered 28/2, 2011 at 16:22 Comment(2)
Do you mean with "changes the backing list to the table" a direct access to the underlying SWT-Table component, or are they also working on the viewer? A snippet would be helpfulSalicylate
@Tom Seidel No, I mean there is a ContentProvider (class ContentProvider extends AbstractContentProvider implements IStructuredContentProvider, IItemListViewer) used by the TableViewer which may change the items it contains at runtime.Culosio
M
7

Seems like refresh() method is called after the viewer is disposed (closed?). You can avoid this exception by checking:

public void refresh() {
   if (viewer != null && !viewer.getControl().isDisposed()) {
      // Actual refresh code
   }
}
Middlings answered 5/6, 2011 at 4:55 Comment(1)
it is just a workaround, which you would have to use basically everywhere. This error is thrown, if some disposed widgets are not garbage collected, I got this error very often when widget has been used as listener somewhere and it was not unregistered after being disposed of. The solution proposed by spektom only avoids the problem on one place, not actually fix it, I would use it as a last instance. First I would check, if your widget is referenced somewhere after it is disposed of.Hyson
T
2

Try use display.isDisposed() like this.

    shell.getDisplay().asyncExec(new Runnable()
    {
        @Override
        public void run ()
        {
            if(!display.isDisposed() && !disposing)
            {
                              //you source code
            }
        }
    });

But remember that isDisposed() return true then disposing end. Thats why you shod use flag

disposing = true;

display.dispose();

disposing = false;

Threefold answered 23/8, 2013 at 10:43 Comment(0)
L
1

Just create a new work-space. Import your projects. It worked for me. :)

Ledaledah answered 22/1, 2013 at 5:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.