aya icon indicating copy to clipboard operation
aya copied to clipboard

Threading breaks `.U` and Canvas in AyaIDE

Open BlazingTwist opened this issue 1 year ago • 1 comments

#92 introduced an issue where the IDE seems to deadlock itself when opening Swing UI while running code from the editor.

Steps to reproduce

  • put "test" .U in the Editor Window
  • Run the Editor

Results in: image


Probable cause:

https://github.com/aya-lang/aya/blob/3ab481f2eb3d14aac7d9a154db3c44a9bff12cf6/src/ui/EditorWindow.java#L224C4-L224C50

This is executed by the Swing Thread. Hence the Swing thread is waiting for the instruction to return. Which in turn is waiting for the Swing Thread to close the popup.


Possible fix

Wrapping it in a new Thread seems to work. I have not thought about possible side-effects this causes though

			new Thread(() -> {
				try {
					ExecutionResult res = _aya.waitForResponse();
					InteractiveAya.printResult(StaticData.IO, res);
				} catch (ThreadError e) {
					StaticData.IO.err().print(e.getMessage());
				} catch (InterruptedException e) {
					e.printStackTrace(StaticData.IO.err());
				}
			}).start();

BlazingTwist avatar Oct 31 '24 19:10 BlazingTwist

I'm able to reproduce the issue with the dialog instructions as well.

Run in editor:

import ::dialog
"test" dialog.alert

Thanks for the report, I'll dig into this a bit more to see what the best solution would be.

nick-paul avatar Nov 01 '24 03:11 nick-paul