-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Assertion callbacks #100
Assertion callbacks #100
Conversation
…ertion-exceptions
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.
Looks good! I've left some minor comments. Please address them and the PR will be ready for a merge.
imgui-binding/src/main/java/imgui/assertion/ImAssertCallback.java
Outdated
Show resolved
Hide resolved
imgui-binding/src/main/java/imgui/assertion/ImAssertCallback.java
Outdated
Show resolved
Hide resolved
Co-authored-by: SpaiR <klimbetoo@gmail.com>
LGTM! As always, great job! |
Thank you sooooo much for the addition! You have encouraged me to continue working on a project and saved me so many future debugging headaches lol 🙏 very appreciated |
No problem @serivesmejia, this was something that I believe will help many people trying to debug issues, including myself. |
This PR implements the ability to receive a callback in java from the native layer upon an
IM_ASSERT(_EXPR)
call.The default callback which is registered by ImGui upon initialization will print the assertion, file and line number, along with the stack trace to pinpoint the call within the user application code that cause the assertion failure.
Example:
Here you can see the call to
popStyleColor
caused the assertion failure.The default callback can be overridden by the user by calling:
The default Dear ImGui assertion behavior can be restored by setting the callback to null:
Some details about the implementation:
Due to how ImGui expects execution to end upon an assertion failure, it is not capable of continuing execution after a failed assertion. As such, this implementation will call a
System.exit(1)
after the user callback has completed. It is not possible to throw an exception to terminate execution as the native call must complete before the exception propagates up the stack to become uncaught and terminate the application. In the event that the callback throws an exception, it is caught and printed with a warning, along with some basic information about the assertion.Please see the javadocs for more information.
Please let me know what you think.
Thank you,
Trevor