简体   繁体   中英

Access Violation in debug mode, but fine in release mode

I am working on this problem for two days and this is driving me mad as I am still quite new to C++. This violation access problem may be quite easy to you and may be answered thousands of times. But my lack of C++ knowledge make me even unable to identify the same problem ever answered.

OK here is my problem:

1. The major code is in a DLL. I am using Visual Studio 2008

2. This DLL called 3 external libraries: boost, tinyXML and SRILM (a NLP toolkit).

3. The error says: Unhandled exception at 0x5f4f068f (TextNormalizerAPI.dll) in tester.exe: 0xC0000005: Access violation reading location 0x00000000. , occurred only in Debug mode. And the error line was caused by an initialization of a boost::regex object ( patUsername = regex("^\\\\W*@[A-Za-z]"); ) in my code, but the actual position was deeply inside the boost library, as shown in below figure:

错误发生在boost lib中,不在我的代码中

**in most cases, I am not supposed to change the source code of Boost lib, isn't it? **

4. This error occurred only in Debug version, not in Release version.

5. I replace the whole solution with a old but fault-free version which worked properly in Debug mode. Yet immediately after I generating a Release version of this solution, error occurred in Debug mode!

UPDATE:

6. Thank you guys! I just tried something and found out that even a simple define a regex object in the first line of the entry of DLL will incurred this error! Any ideas?

7. yet initialize a regex object in the first line in the main() of the caller of this dll will not incur this problem.

Hope this description will help you recall something and give me some hint.

I want to ask:

what's the usual strategy to narrow down and spot the problem? thank you!

查看您的代码,您可能需要验证您的m_position值是否有效……我在您的代码中看到一个escape_type_class_jump标签,因此goto或您用来跳转到该标签的任何机制(我不能从屏幕截图中判断)可能会绕过正在执行的任何检查,以验证您的位置增量仍然有效。

It looks to me like "this" (ie, the basic_regex_parser) is NULL, and it's trying to call a method on a NULL object, which obviously doesn't work well. If "this" is indeed NULL (you can tell by looking in the "Locals" tab, then I would go up the call stack to the "basic_regex_implementation" level and see what's going on there -- where is this NULL value coming from? In general, looking at different levels of the call stack, and at the variables' values in those levels, will be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM