eclipse / nebula

Nebula Project
https://eclipse.org/nebula
Eclipse Public License 2.0
85 stars 98 forks source link

RichText: SWTException when calling setText() multiple times consecutively #458

Closed cpfeiffer closed 10 months ago

cpfeiffer commented 2 years ago

I've modified the rich text editor sample to call setText() twice (when pressing the "Set Text" button). This causes a crash:

Exception in thread "main" org.eclipse.swt.SWTException: Permission denied.
    at org.eclipse.swt.browser.WebBrowser$EvaluateFunction.function(WebBrowser.java:195)
    at org.eclipse.swt.browser.WebSite.Invoke(WebSite.java:809)
    at org.eclipse.swt.browser.WebSite$7.method6(WebSite.java:182)
    at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:120)
    at org.eclipse.swt.internal.ole.win32.COM.VtblCall(Native Method)
    at org.eclipse.swt.internal.ole.win32.IDispatch.Invoke(IDispatch.java:65)
    at org.eclipse.swt.ole.win32.OleAutomation.invoke(OleAutomation.java:575)
    at org.eclipse.swt.ole.win32.OleAutomation.invoke(OleAutomation.java:538)
    at org.eclipse.swt.browser.IE.execute(IE.java:1202)
    at org.eclipse.swt.browser.WebBrowser.nonBlockingExecute(WebBrowser.java:400)
    at org.eclipse.swt.browser.WebBrowser.evaluate(WebBrowser.java:450)
    at org.eclipse.swt.browser.WebBrowser.evaluate(WebBrowser.java:406)
    at org.eclipse.swt.browser.Browser.evaluate(Browser.java:666)
    at org.eclipse.swt.browser.Browser.evaluate(Browser.java:615)
    at org.eclipse.nebula.widgets.richtext.RichTextEditor.setText(RichTextEditor.java:419)
    at org.eclipse.nebula.widgets.richtext.example.RichTextEditorExample$5.widgetSelected(RichTextEditorExample.java:135)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:252)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4209)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1043)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4026)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3626)
    at org.eclipse.nebula.widgets.richtext.example.RichTextEditorExample.main(RichTextEditorExample.java:59)

Here's the change, but to try it, comment out the added getText() which leads to a crash on startup (#457). https://github.com/GEBIT/nebula/commit/092e69d16e6eedbbbc62cbf976c0d992f2e836a9

fipro78 commented 2 years ago

Will you provide a patch? Any idea how to solve that case? As far as I understood, there is no real sync mechanism on calling a BrowserFunction. That means, from the Java perspective the call to a BrowserFunction is triggered, and there is no way to sync the browser call with the Java processing, e.g. to wait that another call is triggered until the previous call is finished. At least I am not aware of such a synchronization.

Any ideas or hints welcome.

cpfeiffer commented 2 years ago

TBH, I hoped someone else had an idea about this :joy:

This could also just be a problem on Windows/IE and be an SWT issue. At least, I cannot reproduce it on Linux/WebKit2, but then I also suffer from #434 atm.

fipro78 commented 2 years ago

Unfortunately I have no idea on this. I think I had this issue when I created the example and that is why the ModifyListener is not directly updating the RichTextEditor. Every idea I had on this did not work (queuing, synchronizing, delay, ...)

Not sure what to do here. If nobody else has an idea on this, I tend to close as WONTFIX. But we can also keep it open if someone comes up with an idea.

cpfeiffer commented 2 years ago

The only possible improvement I see is wrapping Browser.evaluate()with a try-catch and improving the error message. The SWTException's code is SWT.ERROR_FAILED_EVALUATE.

That way, other people wouldn't need to spend time debugging this.

lcaron commented 10 months ago

try / catch added, thank you