I have an application that runs just fine in the debug build, but when I start it in the release build, I get a
unhandled Exception at 0x0043b134 in myapp.exe: 0xC0000005:
Access violation while reading at position 0x004bd96c
If I click on 'break' it tells me that there are no symbols loaded and the source code can't be displayed.
What can I do in such a situation to track down the problem?
For me, the problem was that a constructor was initializing 2 member variables in the wrong order. i.e. not the same order that they were declared in.
I'm surprised that initialization order actually makes any difference.
Are you sure that both releases use the same
.dll
? I spend an hour wondering why my program did compile in debug mode but not in release mode and I just forgot to update the dll's in the release folder.It could be two things:
To rule out the former, try redefining
assert
as an empty operation in the debug build. If the absence of some assertion causes the crash, you will see it. Otherwise, it's something else.Also, I assume you have version control. Did this just start happening? You can analyze the code changes from last week.
Finally, even in the absence of a crash in debug mode, running a memory checker tool may be useful to spot incorrect memory access.
Without looking at the code, it is hard to tell what is bad. All the above suggestions are good and helpful but what I have found most helpful fixing this kind of things is to run certain parts of program in chunks. i.e., comment out a lot of code/functionality and then run the program and see if it crashes. If it doesn't, the uncomment some functionality and then re-run again and so on. This way you will be able to narrow down the problem to the exact code that is causing this.
In most of the cases this happens due to some Buffer overruns which Debug builds can guard against.