[API] Add a mechanism for Dear ImGui assertion callbacks (#100)

* Syncing wip to github

* Assertion callback works

* Restore example that does not crash

* Add comment in build script. Merge with upstream.

* Fix assert always triggering

* Resolve jvm env at runtime to prevent looking up bad stack address

* Fixed EXCEPTION_ACCESS_VIOLATION within native code after callback was complete.

* Fix linting errors

* Change ImGui to Dear ImGui

Co-authored-by: SpaiR <klimbetoo@gmail.com>

* Move jvm native layer to its own header/source

Co-authored-by: SpaiR <klimbetoo@gmail.com>
This commit is contained in:
Trevor FlynnandSpaiR authored and GitHub committed 2021-12-26 14:11:56 +02:00
1 parent adf9d5fe4e
commit 74203bc333
15 files changed
+286 -24

No files matched your search

@@ -1,5 +1,6 @@
package imgui;
import imgui.assertion.ImAssertCallback;
import imgui.flag.ImGuiCond;
import imgui.flag.ImGuiDragDropFlags;
import imgui.flag.ImGuiInputTextFlags;
@@ -76,6 +77,14 @@ public class ImGui {
ImFontAtlas.nInit();
ImGuiPlatformIO.init();
nInitInputTextData();
setAssertCallback(new ImAssertCallback() {
@Override
public void imAssertCallback(String assertion, int line, String file) {
System.err.println("Dear ImGui Assertion Failed: " + assertion);
System.err.println("Assertion Located At: " + file + ":" + line);
Thread.dumpStack();
}
});
}
private static String resolveFullLibName() {
@@ -131,7 +140,9 @@ public class ImGui {
*/
private static native void nInitJni(); /*
Jni::InitJvm(env);
Jni::InitCommon(env);
Jni::InitAssertion(env);
Jni::InitCallbacks(env);
Jni::InitBindingStruct(env);
*/
@@ -190,6 +201,17 @@ public class ImGui {
ImGui::SetCurrentContext((ImGuiContext*) ptr);
*/
/**
* Set a custom assertion callback for ImGui assertions.
* Take note: Any custom assertion callback SHOULD NOT throw any exception.
* After any callback the application will be terminated, any attempt to bypass this behavior
* will result in a EXCEPTION_ACCESS_VIOLATION from within the native layer.
* @param callback The custom ImGui assertion callback
*/
public static native void setAssertCallback(ImAssertCallback callback); /*
Jni::SetAssertionCallback(callback);
*/
// Main
/**