question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugging "assertion failed"

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
SpaiRcommented, 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.

1reaction
tlf30commented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertion Failed Dialog Box - Visual Studio (Windows)
An assertion statement specifies a condition that you expect to hold true at some particular point in your program. If that condition does...
Read more >
Debug assertion failed - Stack Overflow
I get the "Debug assertion failed" error when my program ends. I've been trying to fix it for a long time and just...
Read more >
How to solve "Debug Assertion Failed" error
I had written a programme , it successfully compiled but when it runs it shows an error message "Debug Assertion Failed". Please tell...
Read more >
Microsoft Visual C++ Debug Library. Debug Assertion Failed ...
An error log is being created. ... Debug Assertion Failed! ... For information on how your program can cause an assertion failure, see...
Read more >
How to fix 'debug assertion failed' - Quora
This is a very difficult question to answer with such little information, but a debug assertion failure is detected by a test in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found