what to do if debug runs fine, but release crashes

2019-01-26 15:07发布

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?

10条回答
祖国的老花朵
2楼-- · 2019-01-26 15:37

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.

查看更多
smile是对你的礼貌
3楼-- · 2019-01-26 15:38

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.

查看更多
看我几分像从前
4楼-- · 2019-01-26 15:45

It could be two things:

  • One or more of your assertions does necessary work apart from the check itself
  • Something else

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.

查看更多
\"骚年 ilove
5楼-- · 2019-01-26 15:50

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.

查看更多
登录 后发表回答