-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add better jni error reporting inside the godot editor #627
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5e10006
Add better jni error reporting
chippmann b389796
Describe exception in the case of a jni error as well.
chippmann 66bfaf5
Fix test function name
chippmann 7c4cc62
Remove unnecessary comments
chippmann 2f3d099
Change init
chippmann f179076
Fix casing
chippmann 5d31baa
Remove exception handling
chippmann 7626539
Change tools_enabled to debug_enabled
chippmann 2f61f59
Move variable declaration into if
chippmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
harness/tests/src/main/kotlin/godot/tests/exception/ExceptionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package godot.tests.exception | ||
|
||
import godot.Node | ||
import godot.annotation.RegisterClass | ||
import godot.annotation.RegisterFunction | ||
|
||
@RegisterClass | ||
class ExceptionTest: Node() { | ||
|
||
@RegisterFunction | ||
fun throwException() { | ||
throw RuntimeException("Test exception") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extends "res://addons/gut/test.gd" | ||
|
||
|
||
func test_exception_printing_in_editor() -> void: | ||
var exception_test_script = load("res://scripts/godot/tests/exception/ExceptionTest.gdj").new() | ||
exception_test_script.throw_exception() | ||
assert_true(true) # fake assert; exception printed to console and godot editor | ||
exception_test_script.free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,36 @@ namespace jni { | |
return env->ExceptionCheck(); | ||
} | ||
|
||
void Env::exception_describe() { | ||
String Env::exception_describe() { | ||
#ifdef DEBUG_ENABLED | ||
jthrowable e = env->ExceptionOccurred(); | ||
|
||
if (e != nullptr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
jclass string_writer_class {env->FindClass("java/io/StringWriter")}; | ||
jmethodID string_writer_constructor {env->GetMethodID(string_writer_class, "<init>", "()V")}; | ||
jobject string_writer {env->NewObject(string_writer_class, string_writer_constructor)}; | ||
|
||
jclass print_writer_class {env->FindClass("java/io/PrintWriter")}; | ||
jmethodID print_writer_constructor {env->GetMethodID(print_writer_class, "<init>", "(Ljava/io/Writer;)V")}; | ||
jobject print_writer {env->NewObject(print_writer_class, print_writer_constructor, string_writer)}; | ||
|
||
jclass throwable_class {env->FindClass("java/lang/Throwable")}; | ||
jmethodID print_stack_trace_method {env->GetMethodID(throwable_class, "printStackTrace", "(Ljava/io/PrintWriter;)V")}; | ||
env->CallVoidMethod(e, print_stack_trace_method, print_writer); | ||
|
||
jmethodID to_string_method {env->GetMethodID(string_writer_class, "toString", "()Ljava/lang/String;")}; | ||
auto j_stack_trace_string {(jstring) env->CallObjectMethod(string_writer, to_string_method)}; | ||
|
||
const char* c_stack_trace {env->GetStringUTFChars(j_stack_trace_string, nullptr)}; | ||
String stack_trace {c_stack_trace}; | ||
env->ReleaseStringUTFChars(j_stack_trace_string, c_stack_trace); | ||
|
||
return stack_trace; | ||
} | ||
#else | ||
env->ExceptionDescribe(); | ||
#endif | ||
return {}; | ||
} | ||
|
||
void Env::exception_clear() { | ||
|
@@ -48,9 +76,13 @@ namespace jni { | |
|
||
void Env::check_exceptions() { | ||
if (exception_check()) { | ||
exception_describe(); | ||
String exception {exception_describe()}; | ||
exception_clear(); | ||
HANDLE_JVM_EXCEPTIONS(true, "An exception has occurred!"); | ||
|
||
if (exception.is_empty()) { | ||
exception = "An exception has occurred!"; | ||
} | ||
HANDLE_JVM_EXCEPTIONS(true, exception); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplification: define it in following if