WIERD VC6 compiler problems!


I know this probably doesn’t belong here but I don’t know where it does belong. If you do please let me know…

I have a problem. Its a wierd problem. I compile my OpenGL programs using VC6. I usually leave all the default settings in the Debug profile. Then just switch it to the Release profile when I’m finished. So it applied the optimizations and the result is alot smaller.

But I’ve just tried that with my latest program and I’ve gotten a wierd result. When the /Ox flag is on (optimizations of any kind be it speed or size or whatever) my functions don’t work the same. For example one of my functions calculates the normal of a polygon right? Simple enough. Yet the result is always 0. I’ve checked the data being passed to it and its correct. Yet the compiler is giving the result of a - b as 0. No matter what a or b are?!?!?!

How can that be possible? Its a simple math problem and its getting the answer wrong???

And yet with the Debug profile it give the correct result???

HELP ME! Pleeease!


A mean person would say “this is not an OpenGL question”.

A slightly more helpful person would tell you that the debugger in MSVC is quite confused about where results live in release mode code. The only way to REALLY know is to look at the disassembly and figure out which register to find it in. Or, if you can re-run, put in a store to a global variable, and then look at the value of that global once it has been updated – which may be at the end of the function, rather than in “sequence”, because of code reordering.

Debugging is the most important skill a programmer can have.

Thanks for the reply.

I know its not really an OpenGL problem. But I wasn’t sure who else to ask…

I’m not expert with debugging or reading the assembled code or anything but I did try that with a global variable and I tried writing all the results to a file etc.

This function is called 100s of time. So I tried just calling it once, tried re-writing it. Tried all sorts. But the result is always 0 in release mode.

I don’t get it?

That is called optimisations tweak time!!

In the project options, you can select/unselect which optimisations you want. What you do, is you select/unselect each of the optimisations one at a time and find out which ones gives you the problem. From there you can maybe figure out a solution! I say might be because it could simply be compiler bug that you cannot work around.

Don’t blame VC too quickly as Gorg suggest.

I often got the problem that programs made under VC were doing different things under Debug and Release mode, but those problems were ALWAYS because of mistakes in the source code.

In release mode try using screen or file output to track your variables.

PS: If you really think it’s VC’s fault, install the VS6.0 SP5 if you haven’t done it yet.

GPSnoopy : I did not exactly blame VC++ . I just told him to check the optimisations. The rest of the text was just filling , because he checking the optimisations did not find a culprit, than he would come back ask for help and THEN I would have told him to check his stuff.

Checking the optimisations does not take much time if your software is fast to build.

Thanks for the help guys.

I did try fiddling with the optimizations. Seems if I select anything from the optimization from down box besides Default or None (DEBUG) it happens. Tried flicking on and off the other tick boxes but it happend with all??

My first thought when I saw this problem (its an obviously problem… every polys normal is 0,0,0 so its kinda dark), my first thought was that something was wrong with the code. But then I couldn’t work out why it would work in Debug but not Release. The code is the same in both…?