Hello expert!
I am writing a subproject called VISP for a medical application. The project is written using the IDE of Microsoft Visual Studio 2008 under C++ (with GDI+). Up to now, I had a lot of trouble learning GDI+ & how to write an application under Windows, but that is over now. The application runs up to the point I have programmed well. That was, at least, my perception until yesterday.
To pass the subprogram to the test people, I have to place the code to the disposal after compiling it in the release configuration. The compilation & linkage is without problems.
The problem
When running the program with some breakpoints, the code behaves differently. Some of the breakpoints are skipped, some code lines are accessed out of order (first line 3, then line 1, line 2 is skipped). That may be some rearrangement done by the compiler in the release configuration. But my problem is that the code doesn’t run after a few dialogues open & terminates with the error message
Microsoft Visual Studio
/!\ Microsoft Visual Studio C Runtime Library hat einen schwerwiegenden Fehler in
VISPt2.exe gefunden.
Klicken Sie auf „Unterbrechen“, um das Programm yu debuggen, oder auf
„Weiter“, um es zu beenden.
[Unterbrechen] [Weiter]
… that reads
Microsoft Visual Studio C Runtime Library has encountered a fatal error in VISPt2.exe. Please click „Interrupt“ to debug the program or „Continue“ to quit.
in English.
Analysis
I tried to find out what is going on. I have a lot of methods that have a const ¶meter-type interface. The call by reference is just to reduce the time of calling the method. In the debug mode, this is not a problem. In the release mode, the objects are in some methods deleted after accessed first. This is not always the case. One method called
enum RectangleCorner
{
rcUpperLeft = 0,
rcLowerLeft,
rcLowerRight,
rcUpperRight,
rcMaximum = rcUpperRight
};
class Quadrant;
typedef vector Quadrants
[…]
void Constants::ReserveObjectQuadrants(Quadrants &quadrants)
{
const BYTE nQUADRANTS_SIZE = (const BYTE)quadrants.size();
assert(nQUADRANTS_SIZE = rcMaximum) ? rcLowerRight : rcLowerLeft;
if(nQUADRANTS_SIZE > 0)
{
BYTE nX1 = quadrants[rcUpperLeft].GetX(), nX2 = quadrants[nINDEX2].GetX();
[…]
…has it’s quadrants object for the first three calls with four or two elements. This is OK. But at the fourth call, the object is shown as uninitialised in the debugger. This causes a crash of the program.
Remediation
I tried to get rid of this and other similar problems by changing the interface to call-by-value. But I have still the same problems. In the above code part, some of the variables defined cannot be debugged when running the program in the release configuration, such as nQUADRANTS_SIZE or nINDEX2. This may be the result of code optimation and is not my principle problem. Recompilation of the code in debug results in a fully-functional code.
My questions
Do you have experience with differences between debug & release behaviour?
What would you recommend me to do to get it run in the release configuration?
Thank you for your help!