This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcj win32 frustration


BM> Could you post this test case? Maybe someone will be able to reproduce
BM> it and help figure out the problem.

BM> Regards

BM> Bryce

It is just the standard Eclipse browser snippet in a stacklayout.

Crashes with an NPE with gcc-win32 3.5 at -Os, works on one machine at
-O0 but not any others.

3.4.1 crashes similarly. But sometimes it is like a crap shoot and
will just work. It is incredibly frustrating..

Regards,
Rutger Ovidius
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.browser.StatusTextEvent;
import org.eclipse.swt.browser.StatusTextListener;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class WB {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());

    Clipboard cb = new Clipboard(display);
    String s = "Time: " + System.currentTimeMillis();
    cb.setContents(new String[]{s}, new Transfer[]{TextTransfer.getInstance()});
    System.out.println(s + "==" + cb.getContents(TextTransfer.getInstance()));

    final Composite parent = new Composite(shell, SWT.NONE);
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));
    final StackLayout layout = new StackLayout();
    parent.setLayout(layout);

    final Composite browserComposite = new Composite(parent, SWT.NONE);
    final Composite emptyComposite = new Composite(parent, SWT.NONE);
    emptyComposite.setLayout(new FillLayout());
    createBrowser(browserComposite);

    new Button(emptyComposite, SWT.NONE).setText("Empty");
    layout.topControl = emptyComposite;

    Button b = new Button(shell, SWT.PUSH);
    b.setText("CrashMe");
    b.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        if (layout.topControl == emptyComposite)
          layout.topControl = browserComposite;
        else
          layout.topControl = emptyComposite;

        parent.layout();
      }
    });

    shell.open();
    while (shell != null && !shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }

  }

  // snippet128
  public static void createBrowser(Composite composite) {
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    composite.setLayout(gridLayout);
    ToolBar toolbar = new ToolBar(composite, SWT.NONE);
    ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
    itemBack.setText("Back");
    ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
    itemForward.setText("Forward");
    ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
    itemStop.setText("Stop");
    ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
    itemRefresh.setText("Refresh");
    ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
    itemGo.setText("Go");

    GridData data = new GridData();
    data.horizontalSpan = 3;
    toolbar.setLayoutData(data);

    Label labelAddress = new Label(composite, SWT.NONE);
    labelAddress.setText("Address");

    final Text location = new Text(composite, SWT.BORDER);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    data.grabExcessHorizontalSpace = true;
    location.setLayoutData(data);

    final Browser browser = new Browser(composite, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    data.horizontalSpan = 3;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    browser.setLayoutData(data);

    final Label status = new Label(composite, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    status.setLayoutData(data);

    final ProgressBar progressBar = new ProgressBar(composite, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.END;
    progressBar.setLayoutData(data);

    /* event handling */
    Listener listener = new Listener() {
      public void handleEvent(Event event) {
        ToolItem item = (ToolItem) event.widget;
        String string = item.getText();
        if (string.equals("Back"))
          browser.back();
        else if (string.equals("Forward"))
          browser.forward();
        else if (string.equals("Stop"))
          browser.stop();
        else if (string.equals("Refresh"))
          browser.refresh();
        else if (string.equals("Go"))
          browser.setUrl(location.getText());
      }
    };
    browser.addProgressListener(new ProgressListener() {
      public void changed(ProgressEvent event) {
        if (event.total == 0)
          return;
        int ratio = event.current * 100 / event.total;
        progressBar.setSelection(ratio);
      }

      public void completed(ProgressEvent event) {
        progressBar.setSelection(0);
      }
    });
    browser.addStatusTextListener(new StatusTextListener() {
      public void changed(StatusTextEvent event) {
        status.setText(event.text);
      }
    });
    browser.addLocationListener(new LocationListener() {
      public void changed(LocationEvent event) {
        location.setText(event.location);
      }

      public void changing(LocationEvent event) {
      }
    });
    itemBack.addListener(SWT.Selection, listener);
    itemForward.addListener(SWT.Selection, listener);
    itemStop.addListener(SWT.Selection, listener);
    itemRefresh.addListener(SWT.Selection, listener);
    itemGo.addListener(SWT.Selection, listener);
    location.addListener(SWT.DefaultSelection, new Listener() {
      public void handleEvent(Event e) {
        browser.setUrl(location.getText());
      }
    });

  }
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]