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

Catch and log all uncaught exceptions propagated from simpleUpdate(). #1952

Closed
wants to merge 2 commits into from

Conversation

danielperano
Copy link
Member

I recently encountered an issue where exceptions were propagating out of my code and silently being swallowed without the usual "uncaught exception" window being shown or any logging. Since jME already tries to handle this case, I was surprised after a couple of hours of debugging to find that the origin was an exception coming from within simpleUpdate() (in my case it happened in a subtle and rather difficult to debug scenario).

The solution I added in my codebase was wrapping the body of simpleUpdate() in a try-catch block and logging the stack trace. Since SimpleApplication aims to be a consistent and easy to use one-stop-shop for app-level concerns, it would be nice if it handled this situation as well.

I'm not entirely convinced that this is the best way to do this (especially given jME's existing uncaught exception handling), but it seems a reasonable starting point for further discussion - feedback is welcomed.

@Ali-RS
Copy link
Member

Ali-RS commented Feb 12, 2023

without the usual "uncaught exception" window being shown

Just a note, if you are using JME 3.6, you need to add jme3-awt-dialogs into the Gradle dependencies if you want to show the error dialogs else it will only print the error message to the console.

See:
#1876

https://hub.jmonkeyengine.org/t/next-engine-release/46314/71?u=ali_rs

@danielperano
Copy link
Member Author

danielperano commented Feb 12, 2023

This is on 3.5.1-stable, and I see the AWT exception dialogs for every other uncaught exception that I'm aware of.

@Ali-RS
Copy link
Member

Ali-RS commented Feb 12, 2023

May you please post that uncaught exception (with the full stack trace please and the thread name from which it is thrown) that JME was unable to handle it?

Edit:

And by the way, taking a quick look, JME will only handle uncaught exceptions thrown from "jME3 Main" thread

protected boolean initInThread() {
try {
if (!JmeSystem.isLowPermissions()) {
// Enable uncaught exception handler only for current thread
Thread.currentThread().setUncaughtExceptionHandler((thread, thrown) -> {
listener.handleError("Uncaught exception thrown in " + thread.toString(), thrown);
if (needClose.get()) {
// listener.handleError() has requested the
// context to close. Satisfy request.
deinitInThread();
}
});
}

Can you please confirm that your exception is thrown from "jME3 Main" thread?

Edit2:
Also would be very helpful if you can provide a minimal test case to reproduce this issue.

@danielperano
Copy link
Member Author

I'm going to retract this pull request - while trying to reproduce the stack trace under conditions that this PR would encounter, I discovered that the error being produced was being swallowed within one of my own libraries (an event dispatcher), so it wasn't jME that was ignoring the error because it never actually propagated to jME at all.

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

Successfully merging this pull request may close these issues.

2 participants