PDA

View Full Version : WIERD VC6 compiler problems!



Rob123
02-06-2002, 06:04 PM
Hi

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!

Rob.

jwatte
02-06-2002, 06:12 PM
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.

Rob123
02-06-2002, 06:24 PM
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?

Gorg
02-06-2002, 07:05 PM
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.

GPSnoopy
02-06-2002, 10:39 PM
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.

Gorg
02-06-2002, 10:58 PM
GPSnoopy : I did not exactly blame VC++ http://www.opengl.org/discussion_boards/ubb/smile.gif. I just told him to check the optimisations. The rest of the text was just filling http://www.opengl.org/discussion_boards/ubb/smile.gif, because he checking the optimisations did not find a culprit, than he would come back ask for help and THEN http://www.opengl.org/discussion_boards/ubb/smile.gif I would have told him to check his stuff.

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

Rob123
02-06-2002, 11:48 PM
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....?

Rob.