Debugging "assertion failed"
See original GitHub issueI have been getting various assertion errors that look like this
java: ./imgui.h:1778: const T& ImVector<T>::operator[](int) const [with T = imnodes::{anonymous}::NodeData]: Assertion `i >= 0 && i < Size' failed.
The issue is, I’m not sure how to debug these errors. My application is getting kinda large so it’s not 100% viable to put print statements everywhere (edit: though maybe breakpoints could work i honestly havent tried). I can’t get other debugging features to work. Since the JVM freezes for a few seconds before closing when an assertion error happens, I’m not able to generate a thread dump afterwards, IntelliJ’s debugger and VisualVM aren’t able to retrieve any data from the JVM after an “assertion failed” error happens for the same reason.
I’m not 100% sure how it works, but wouldn’t it be possible to throw a “ImException” when an assertion error happens? That would give a useful stacktrace. For example, how OpenCV does it:
OpenCV Error: Assertion failed (clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE, 0, u->size, alignedPtr.getAlignedPtr(), 0, 0, 0) == CL_SUCCESS) in cv::ocl::OpenCLAllocator::map, file ..\..\..\..\opencv\modules\core\src\ocl.cpp, line 3961
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\ocl.cpp:3961: error: (-215) clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE, 0, u->size, alignedPtr.getAlignedPtr(), 0, 0, 0) == CL_SUCCESS in function cv::ocl::OpenCLAllocator::map
]
at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method)
at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:176)
at test.processor.detect(window.java:66)
at test.window.main(window.java:100)
It throws a Java exception with a useful stack trace when assertion errors happen, I’m not 100% sure if this would be a good and viable idea, neither how that works in the native side (haven’t worked much with JNI) but if there is any possibility making it I’d look forward to it!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
@tlf30 At this point any sort of handling imgui assertions will be good. The best solution will be to throw a java exception. So it will be more intuative to any java developer. I’m not sure if it’s possible, didn’t touch that topic yet. I’ll be happy to see any solution on that problem.
Just as a status update on this, I have an implementation that works. The stack is preserved on the callback from the native code, so it does pinpoint where the assertion failed in the user java code (which is amazing). I am currently trying to track down an
EXCEPTION_ACCESS_VIOLATION
that only occurs with some assertions but not others. It is very specific which ones fail and which ones do not. I am hoping to have a PR soon.