Skip to content
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

Debugging "assertion failed" #86

Closed
serivesmejia opened this issue Oct 15, 2021 · 5 comments · Fixed by #100
Closed

Debugging "assertion failed" #86

serivesmejia opened this issue Oct 15, 2021 · 5 comments · Fixed by #100

Comments

@serivesmejia
Copy link
Contributor

serivesmejia commented Oct 15, 2021

I 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!

@tlf30
Copy link
Contributor

tlf30 commented Dec 14, 2021

The imgui_config.h file can be used to configure a custom assertion, which could be used to create a callback to throw an exception with the assertion error. It would require this project to overwrite that particular file.

If I get some free time I can look at getting something put together. @SpaiR any thoughts on this approach?

Edit: to clarify, this particular feature would be very useful to me for capturing assertion errors to a log file.

Edit 2: I just got off an hour and a half flight, made some headway into this. Doable, but I need to confirm the call stack from java is still in place when the native callback triggers the java exception. I think it should be, but I need to test.

@SpaiR
Copy link
Owner

SpaiR commented Dec 15, 2021

@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.

@tlf30
Copy link
Contributor

tlf30 commented Dec 25, 2021

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.

@tlf30
Copy link
Contributor

tlf30 commented Dec 25, 2021

Initial implementation ready #100. Please let me know what you think.

@SpaiR
Copy link
Owner

SpaiR commented Dec 26, 2021

#100

@SpaiR SpaiR closed this as completed Dec 26, 2021
@SpaiR SpaiR linked a pull request Dec 26, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants