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

Bug 300980

Summary: [TextSizeDetermination] fails with disposed fonts
Product: [RT] RAP Reporter: Benjamin Muskalla <b.muskalla>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 1.3   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
testcase
none
Another test case none

Description Benjamin Muskalla CLA 2010-01-27 07:59:34 EST
There are cases when we access fonts during the dispose phase of a widget. In case the font itself is disposed before (eg. listing to Display dispose event to dispose the resources) can cause exceptions as we try to access these disposed fonts.
Not yet sure how to handle this correctly but I think we should prevent accessing the text size determination during dispose.
Comment 1 Benjamin Muskalla CLA 2010-01-27 08:00:08 EST
Created attachment 157388 [details]
testcase

Here is a testcase which shows the behavior for the Table widget.
Comment 2 Benjamin Muskalla CLA 2010-01-27 11:02:26 EST
Another problem related to this is that Probes that are stored by the TSD can be disposed before the TSD kicks in.

Example:
    Display display = new Display();
    Shell shell = new Shell( display );
    shell.setLayout( new GridLayout( 1, false ) );
    Label label = new Label( shell, SWT.NONE );
    label.setText("sdjfdsjfh");
    final Font font = new Font(display, "foo", 10, SWT.BOLD);
    label.setFont( font );
    display.addListener( SWT.Dispose, new Listener() {
      public void handleEvent( Event event ) {
        font.dispose();
      }
    });
    shell.pack();
    shell.open();
    while( !shell.isDisposed() ) {
      if( !display.readAndDispatch() )
        display.sleep();
    }
    display.dispose();
    return 0;
    
    
Run the snippet and reload the page. The disposed font is still in the queue of the TSD but already disposed which leads to the following exception:

org.eclipse.swt.SWTException: Graphic is disposed
	at org.eclipse.swt.SWT.error(SWT.java:2757)
	at org.eclipse.swt.SWT.error(SWT.java:2677)
	at org.eclipse.swt.SWT.error(SWT.java:2648)
	at org.eclipse.swt.graphics.Font.getFontData(Font.java:168)
	at org.eclipse.swt.internal.graphics.TextSizeProbeStore.createProbeResult(TextSizeProbeStore.java:104)
	at org.eclipse.swt.internal.graphics.TextSizeDeterminationHandler.readProbedFonts(TextSizeDeterminationHandler.java:177)
	at org.eclipse.swt.internal.graphics.TextSizeDetermination.readStartupProbes(TextSizeDetermination.java:169)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:252)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:117)
	at java.lang.Thread.run(Thread.java:619)
	at org.eclipse.rwt.internal.lifecycle.UIThread.run(UIThread.java:80)
Comment 3 Rüdiger Herrmann CLA 2010-01-29 09:50:46 EST
Created attachment 157625 [details]
Another test case
Comment 4 Rüdiger Herrmann CLA 2010-01-29 12:42:07 EST
The snippet from the description now works (with bug 301249 fixed)
Comment 5 Rüdiger Herrmann CLA 2010-01-29 12:44:30 EST
Regarding the attached test case (Table_Test#testDisposedFont) I am not sure if this is a valid use case. Even though SWT seems to gracefully handle this situation, disposing of a font that is still in use looks more like a programming error to me.
Comment 6 Rüdiger Herrmann CLA 2010-02-02 10:29:27 EST
After gathering some more feedback I will close this bug as WONTFIX. Even though SWT seems to handle disposed fonts somehow, it is certainly not considered a valid use case (for RWT at least)