Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimatedLabel Thread hangs after WaitingDialog closed #595

Open
Kapral67 opened this issue Feb 11, 2024 · 4 comments
Open

AnimatedLabel Thread hangs after WaitingDialog closed #595

Kapral67 opened this issue Feb 11, 2024 · 4 comments

Comments

@Kapral67
Copy link

It is possible for the AnimatedLabel::createSpinningLine component's thread to hang after the WaitingDialog that owns it is closed.

A quick fix could be to explicitly call AnimatedLabel::stopAnimation in WaitingDIalog::close (the spinning line would need to become an instance variable of the WaitingDialog class).

Although, I think a better solution would be some fix within the AnimatedLabel class itself.

Proof of Concept:

final DefaultTerminalFactory terminalFactory = new DefaultTerminalFactory();
try (final Screen screen = terminalFactory.createScreen()) {
    screen.startScreen();

    // POC
    final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen);
    final WaitingDialog waitingDialog = WaitingDialog.createDialog("TITLE", "TEXT");
    waitingDialog.showDialog(textGUI, false);
    CompletableFuture.runAsync(() -> {
                         try {
                             Thread.sleep(5000);
                         } catch (final InterruptedException e) {
                             Thread.currentThread().interrupt();
                             throw new RuntimeException(e);
                         } finally {
                             waitingDialog.close();
                         }
                     }, Executors.newSingleThreadExecutor())
                     .exceptionally(e -> {
                         throw new RuntimeException(e);
                     });
    waitingDialog.waitUntilClosed();
    System.out.println("WAIT DIALOG CLOSED");

} catch (final IOException e) {
    throw new RuntimeException(e);
}
@mabe02
Copy link
Owner

mabe02 commented Feb 13, 2024

Interesting, looks like the WeakReference that's supposed to shut down the thread doesn't trigger until you force GC after the window is closed. We should probably improve on that.

@avl42
Copy link
Contributor

avl42 commented Feb 13, 2024 via email

@mabe02
Copy link
Owner

mabe02 commented Feb 20, 2024

I think this will fix it:
#596

@TheFunnyBear
Copy link

Workaround for me:


        private fun waitDialog(
            textGUI: WindowBasedTextGUI,
            action: Runnable
        ) {
            val waitDialog = WaitingDialog.createDialog("TETST", "TEST MESSAGE")

            runBlocking {
                val job = CoroutineScope(Dispatchers.IO).launch {
                    action.run()
                    waitDialog.setCloseWindowWithEscape(true)
                    val robot = Robot()
                    robot.keyPress(KeyEvent.VK_ESCAPE)
                    robot.keyRelease(KeyEvent.VK_ESCAPE)
                }
                waitDialog.showDialog(textGUI, true)

                job.join()
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants