Qt World Summit: Register Today!

How to find a random nil pointer exception

  • Hey guys,

    I have a problem and I'm not sure how to solve it quickly.
    I have an application which is running in many productive environments. Very rarely the application is terminating itself with a nil pointer read exception ("... referenced memory at 0x0000000. The memory could not be read.").

    Nobody is able to reproduce the error and nobody can tell me in what situation it is happening. On top of it, it is happening completely random. Sometimes every few hours, sometimes once in a few days.
    I also ran the application with connected debugger for a few days, but I couldn't reproduce it.

    So my question is, is there any way to catch this exception and give me more details where it happened?
    As the application is quite large I cannot put a few catch blocks here and there to see if I get closer.

    I'm using QT 5.12, application compiled with MSVC2017 64bit.


  • @themts
    It's very difficult :) It's an MSVC issue.

    I can't remember whether Windows Event Log logs this for you. Try your own null-pointer-exception-crash and see!? Whatever happens you will (likely) need the stack trace, not just the location of the excepting code (e.g. knowing it's in, for the sake of argument, strcpy() won't help you as you don't know where that's called from...).

    I think at one point we did something about generating debug symbols to distribute with release-built code to try to track down if anything happened at a customer site. But we either never used it, or found it was too difficult/useless.

    If you want better answers I think you need to Google for something like "MSVC null pointer release build diagnose", and be prepared to wade through whatever you find!

  • I would try and run Heob on your app to see if there are any obvious memory issues. You can use Heob with qt creator in Windows. In Linux you can run valgrind. Search for "Heob Qt" and you should find the page of how to use heob with qt creator.

  • Moderators

    probably the easiest and most accurate is to write a minidump the moment the crash occurs and analyze it then afterwards.
    You can either use the native WinAPI (requires some manual bootstrapping of your application) or use Google Breakpad. There are also Qt wrappers for Breakpad on the web.

    But note the minidump in all cases might not be very useful when you try it on a release build without debug symbols of course.

  • @fcarney I will check it out but on the first view it looks like it's only reporting memory leaks and buffer overruns.

Log in to reply