PDA

View Full Version : Help! Debug Build working fine..but Release Build crashing in VS 2005


celu
11-11-2007, 09:27 AM
Hi..Im working on c++ in VS 2005.Both the debug and release build of my ray tracer was working fine until a couple of days back when I added a scene parser to the project.Now in debug mode the scenes are parsed fine and the image is rendered properly.But in release mode the program just crashes.Error Logs from the release build show that my newly added parser module was behaving wierdly.

I printed out a for loop variable from my parser module,


/* Tested Code */

for(int i=0;i < 100;i++)
{

/* Some code */

printf("%d",i);

/* Some code */

}


/* Output from Error Log */

In Debug mode, the output is fine

0
1
2
3
4
.
.
.
99

and in Release mode, I get wierd results

0
0
0
0
0
.
.

and the loop does not compete 100 itreations??!!

////////////////////////////////////

Then I found that,

- changing my release build configuration 'Basic Runtime Check' value from 'default' to 'both' (/RTC1, equiv. to /RTCsu).
- and changing the release build configuration 'Optimization' value from 'Maximize Speed' (/O2) to 'Disabled'(/Od).


made my release build to work fine just like my debug build.But it's very slow! :(

What are the possible things that I should check in my code to solve this problem?

why does turning off 'Basic Runtime Check' and enabling 'Maximize Speed' optimization make my release build crash?


Im really blinded by this problem...Pls Help!!


celu.

gaia
11-11-2007, 01:15 PM
To quote Asimov: 'Not enough information for a meaningful answer'.

Check for shadowing of the 'i' variable in the 'Some code' portions of the parser loop and check for potentially uninitialized storage which is typically cleared to zero in debug builds. Sorry about the generic answer, but it was a generic question. :)

Sol_HSA
11-12-2007, 04:49 AM
The debug/release build difference is in most cases either
- uninitialized variables or
- overwriting buffers

debug mode usually initializes all variables to some value (in olden days zero, in modern times some rough value like 0xdeadbeef or such - your environment may vary). In release mode the uninitialized variables get whatever value happens to be in the memory, which may be zero, and hence some if:s that come 'true' in debug may end up 'false' in release, for example.

Overwriting buffers can cause very different results in debug and release, because the memory layout is (most likely) different due to debug info, different code size, etc.

celu
11-12-2007, 06:17 PM
Hey thx guys I finally solved the bug...it was a uninitialized char stack array.I was parsing values into it and then using atof() to convert them to float. As it turned out it had garbage value in them in release mode so the converted float values got wierd and hence the crashing!

thx for your pointers...it really helped me narrow down the bug.