简体   繁体   中英

exception in release mode and not in debug mode

When i run this code in debug mode no exceptions appear but in release mode i get this exception :

Unhandled exception at 0x768b4b32 in RealTimeSLT.exe: Microsoft C++ exception: cv::Exception at memory location 0x003de734..

why this problem appear only when release ?and how can i fix it ??

FileStorage fs2(fileName, FileStorage::READ);
fs2.open(fileName, FileStorage::READ);
fs2["Mat"] >> Mat;  
fs2["dMat"]>> dMat; 
fs2.release();

Assuming you're running in VS, choose Debug->Exceptions and click on 'Break When Exception is Thrown'

Run the app under the debugger and see why that exception is thrown and what its complaining - it's most likely something different in the environment the app is running under.

If you need to examine variables then release build makes this hard as the optimiser is likely confusing the debugger. You can probably solve this by turning off optimizations in your release build. However, if its a timing issue this may hide the problem.

Another option is catching the exception being thrown and then logging its internal message - this is normally a function called 'what()' or similar. This very likely will point you to the actual problem. Its likely that you'll want to catch this exception anyway.

If its undefined behavior causing the difference between Release and Debug then its likely the above wont be as much use.

The code looks odd.

Without knowing any more about your FileStorage object, I can see that you've created one on the stack on the first line.

Assuming release() is some kind of reference counting method, fs2.release() will attempt to delete it since the reference count will be zero.

Not good to delete objects that have been allocated on the stack. You'll get a crash.

Either (1), try this instead (ie allocate on the heap)

FileStorage fs2 = new FileStorage(fileName, FileStorage::READ);

(Assuming the object has reference counting semantics built in; check the docs).

Or 2: remove the last line as fs2 will go out of scope as the stack unwinds.

U need to add "*.lib" files to vs project's linker again when U r in release mode. I think this is a bug for opencv after 2.4.1.

In my case, it was because the OpenCV libraries were built with VS2010, and I was using VS2015.

To resolve issue, I changed my Project Properties > General > Platform Toolset to match the toolset used to build the opencv libraries I was linking with.

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