diff --git a/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy b/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy
index 18876dc3..bce85209 100644
--- a/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy
+++ b/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy
@@ -4,6 +4,7 @@ import com.badlogic.gdx.jnigen.*
import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.file.CopySpec
+import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
@@ -53,6 +54,13 @@ class GenerateLibs extends DefaultTask {
}
spec.from(project.rootProject.file('imgui-binding/src/main/native'))
spec.into(jniDir)
+ spec.duplicatesStrategy = DuplicatesStrategy.INCLUDE //Allows for duplicate imconfig.h, we ensure the correct one is copied below
+ }
+
+ //Ensure we overwrite imconfig.h with our own
+ project.copy { CopySpec spec ->
+ spec.from(project.rootProject.file('imgui-binding/src/main/native/imconfig.h'))
+ spec.into(jniDir)
}
//Copy dirent for ImGuiFileDialog
diff --git a/imgui-binding/src/main/java/imgui/ImGui.java b/imgui-binding/src/main/java/imgui/ImGui.java
index a4460800..cdb3d3ba 100644
--- a/imgui-binding/src/main/java/imgui/ImGui.java
+++ b/imgui-binding/src/main/java/imgui/ImGui.java
@@ -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 static void init() {
*/
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 static void setCurrentContext(ImGuiContext ctx) {
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
/**
diff --git a/imgui-binding/src/main/java/imgui/assertion/ImAssertCallback.java b/imgui-binding/src/main/java/imgui/assertion/ImAssertCallback.java
new file mode 100644
index 00000000..6f831b40
--- /dev/null
+++ b/imgui-binding/src/main/java/imgui/assertion/ImAssertCallback.java
@@ -0,0 +1,45 @@
+
+package imgui.assertion;
+
+/**
+ * Callback for native IM_ASSERT calls.
+ */
+public abstract class ImAssertCallback {
+ /**
+ * Called from native code to bring the callback into java side.
+ * Will force the application to terminate with exit code 1 after forwarding the callback, this is required, otherwise
+ * if execution is returned to the native layer, a EXCEPTION_ACCESS_VIOLATION will be thrown.
+ * If the callback throws an exception, it will be caught and printed along with a warning to prevent execution
+ * from returning to the native layer.
+ *
+ * @param assertion The assertion string
+ * @param line The line number of the assertion in the source file
+ * @param file The source file where the assertion occurred
+ */
+ public void imAssert(final String assertion, final int line, final String file) {
+ try {
+ imAssertCallback(assertion, line, file);
+ } catch (Exception ex) {
+ System.err.println("WARNING: Exception thrown in Dear ImGui Assertion Callback!");
+ System.err.println("Dear ImGui Assertion Failed: " + assertion);
+ System.err.println("Assertion Located At: " + file + ":" + line);
+ ex.printStackTrace();
+ }
+ System.exit(1);
+ }
+
+ /**
+ * The assertion callback from ImGui.
+ * Do not throw an exception within this callback, to prevent
+ * execution from returned to the native layer and cause a EXCEPTION_ACCESS_VIOLATION,
+ * the callback will catch any exceptions and print a warning.
+ *
+ * There is no way to catch the assertion and continue execution.
+ * You may however call System.exit(code) with your own exit code.
+ *
+ * @param assertion The assertion string
+ * @param line The line number of the assertion in the source file
+ * @param file The source file where the assertion occurred
+ */
+ public abstract void imAssertCallback(String assertion, int line, String file);
+}
diff --git a/imgui-binding/src/main/native/_binding.h b/imgui-binding/src/main/native/_binding.h
index 5b9197d8..c5c06a13 100644
--- a/imgui-binding/src/main/native/_binding.h
+++ b/imgui-binding/src/main/native/_binding.h
@@ -1,5 +1,7 @@
#pragma once
+#include "jni_jvm.h"
#include "jni_common.h"
#include "jni_callbacks.h"
#include "jni_binding_struct.h"
+#include "jni_assertion.h"
diff --git a/imgui-binding/src/main/native/_imnodes.h b/imgui-binding/src/main/native/_imnodes.h
index 2a2db539..0e2be4b8 100644
--- a/imgui-binding/src/main/native/_imnodes.h
+++ b/imgui-binding/src/main/native/_imnodes.h
@@ -1,5 +1,4 @@
#pragma once
-#include "_base.h"
+#include "_common.h"
#include
-#include "_binding.h"
diff --git a/imgui-binding/src/main/native/_implot.h b/imgui-binding/src/main/native/_implot.h
index 5f7dfb77..3511474b 100644
--- a/imgui-binding/src/main/native/_implot.h
+++ b/imgui-binding/src/main/native/_implot.h
@@ -1,6 +1,5 @@
#pragma once
-#include "_base.h"
-#include "_binding.h"
+#include "_common.h"
#include
#include "implot.h"
diff --git a/imgui-binding/src/main/native/_nodeeditor.h b/imgui-binding/src/main/native/_nodeeditor.h
index 990294b2..85f97013 100644
--- a/imgui-binding/src/main/native/_nodeeditor.h
+++ b/imgui-binding/src/main/native/_nodeeditor.h
@@ -1,9 +1,5 @@
#pragma once
-#include
-#include
+#include "_common.h"
#include
#include
-#include "jni_common.h"
-#include "jni_callbacks.h"
-#include "jni_binding_struct.h"
diff --git a/imgui-binding/src/main/native/_texteditor.h b/imgui-binding/src/main/native/_texteditor.h
index fcc05089..4c2c7ad7 100644
--- a/imgui-binding/src/main/native/_texteditor.h
+++ b/imgui-binding/src/main/native/_texteditor.h
@@ -8,6 +8,5 @@
#include
#include