Skip to content

[Edge] No more handle exceptions from Edge browser #339

@vogella

Description

@vogella

In our RCP application we see no more handle exceptions during startup if we use Edge. This does not happen all the time, there seems to be a race condition or the error is reported incorrectly similar to https://bugs.eclipse.org/bugs/show_bug.cgi?id=576196.

If the user starts again the RCP application, the errors does not happen again, sometimes is takes 3-4 attempts to start the application. We are using latest version from https://developer.microsoft.com/de-de/microsoft-edge/webview2/#download-section, currently 104.0.1293.63 pointing to the download with -Dorg.eclipse.swt.browser.DefaultType=edge -Dorg.eclipse.swt.browser.EdgeDir=c:\PROGRA~1\WebView2 in the runtime arguments.

This happens in the Edge.createmethod, relevant stack trace:

org.eclipse.swt.SWTError: No more handles [0x8007139f]
at org.eclipse.swt.SWT.error(SWT.java:4944)
at org.eclipse.swt.browser.Edge.error(Edge.java:190)
at org.eclipse.swt.browser.Edge.create(Edge.java:343)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)
at de.example.rcp.base.views.NavigationPanelView.createPartControl(NavigationPanelView.java:242)

Here is the code which triggers the exception:

		try {
			if (hiddenBrowser == null || hiddenBrowser.isDisposed()) {
				hiddenBrowser = new Browser(bar, SWT.EDGE);
				hiddenBrowser.setBounds(0, 0, 0, 0);
				hiddenBrowser.setVisible(false);
			}
		} catch (Exception  | Error  e) {
			LOG.warn("Unable to create hidden browser", e);
		}

callAndWait seems to spins the event queue, maybe this causes the other thread to sync with main thread and to dispose the composite?

static int callAndWait(long[] ppv, ToIntFunction<IUnknown> callable) {
	int[] phr = {COM.S_OK};
	IUnknown completion = newCallback((result, pv) -> {
		phr[0] = (int)result;
		if ((int)result == COM.S_OK) {
			ppv[0] = pv;
			new IUnknown(pv).AddRef();
		}
		return COM.S_OK;
	});
	ppv[0] = 0;
	phr[0] = callable.applyAsInt(completion);
	completion.Release();
	Display display = Display.getCurrent();
	while (phr[0] == COM.S_OK && ppv[0] == 0) {
		if (!display.readAndDispatch()) display.sleep();
	}
	return phr[0];
}

The incorrect behavior reported via https://bugs.eclipse.org/bugs/show_bug.cgi?id=576196 can be reproduced with the following snippet.

	public void createComposite(Composite parent) {
		parent.setLayout(new GridLayout(1, false));

		for (int i = 0; i <= 10; i++) {
			System.out.println("Iteration " + i);
			Composite c = new Composite(parent, SWT.NONE);
			Display.getCurrent().asyncExec(new Runnable() {

				@Override
				public void run() {
					c.dispose();
				}
			});
			Browser browser = null;
			if (!c.isDisposed()) {
				browser = new Browser(c, SWT.EDGE);
			}
			if (browser != null) {
				browser.dispose();
			}
		}

	}

Expected behavior

Correct error message or even better, just working.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)

  2. JRE/JDK version

Java 11

Version since

Still present in latest I-Buil

Workaround (or) Additional context

Start again the RCP application.

Metadata

Metadata

Assignees

Labels

WindowsHappens on Windows OSbugSomething isn't workingedgeEdge Browser

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions