Reputation: 11
my program executes exactly as desired when i run the debugger even with no breakpoints
when i run without debugging, i get a debug error
"This application has requested the Runtime to terminate it in an unusual way."
At one point, I call a function that sets a variable called currCode
(an integer)
currCode = function();
//this throws debug error
If i add a cout of the variable currCode
between this line and the next line, the program works fine with or without the debugger.
currCode = function();
cout << currCode; //this works!
Upvotes: 0
Views: 1967
Reputation: 57749
There are many likely reasons for errors appearing in a program run directly from executable and one run by the debugger. Here are a few common ones:
Again, the above are the most common.
Many debuggers will inadvertantly initialize your variables for you. A program run directly from an executable may not initialize the variable area, the way you expect. In the embedded systems world, this usually means not at all. So, get in the habit of initializing all variables, preferably when you declare them.
Debuggers are nice and want to provide you with a nice experience, so they load a number of shared or dynamically linked libraries before your program is executed. Some of these libraries you will have to explicitly load.
Usually not common, but programs executing without a debugger run at different rates than those run a full speed with a debugger. This can make delay loops (spin loops) be have differently. Data buffers can have longer time to fill when using a debugger. When in doubt, use print statements in the release version to help narrow the location of the issue.
Debuggers usually provide code to protect your program from overrunning the stack, heap and other areas of memory. This comes with the feature to detect wild pointers and accessing data from invalid addresses. Also, debuggers want to protect what little memory the OS gives to them (they have to share memory with your program). A program running without a debugger can mess up stacks and heaps without any detections or generating faults.
Upvotes: 1
Reputation: 11
Might try turning off optimization and see if you still get the problem.
Upvotes: 1