Skip to main content
GameDev.net gamedev.net
🔒 Locked

Different when compiled as release code

Started by MotionCoil Jul 29, 2007 at 7:45 AM 2 replies 1.2k views
Original Post
MotionCoil
MotionCoil
Hey While I slowly convert a lot of our engine modules over to the project I'm coming across more and more weird things. At this point the same code compiled under debug configuration and release configuration yields different results. Its just the UI portion of the engine and I'm doing small tests to see each aspect works. At the moment i'm just showing a 2D image element- all this does is at initialization loads up an image and sets its dimensions, then at the point of rendering does the following: -Sets the current texture to the one in its texture manager -disables the z buffer -renders all the vertices in its vertex manager -enables the z buffer -sets the current texture to nothing this all works well in a debug build but doesn't work when i put it over to release build- it just doesn't show the image in any way. Apart from that everything else is working ok. Is there any reason why exactly the same code should yield different results in two vastly different configurations? Cheers?
sirob
sirob
Usually the problem with code that doesn't work in release but does in debug is uninitialized variables. Make sure you initialize all variables before using them.
Sirob Yes.» - status: Work-O-Rama.
Spoonbender
Spoonbender
Yes. Debug builds do a lot to set memory to one pattern when it's unallocated, another when it's freed, a third when it's allocated but uninitialized and so on.
Release builds just use whatever happens to be in memory.

So if you rely on some of this without knowing it, you get different behavior.
There are also a few optimizations that may in some cases subtly alter program behavior.

I'm guessing your problem is the former. Somewhere in your code, you read out of bounds, and because in a debug build, that memory is initialized to one specific value, that works ok. In release, it just contains garbage.
Or you write out of bounds, and in debug builds, you just write to memory set aside by the compiler to mark "out of bounds", and in release, you just write over something else that was actually important. :P

Or you use a variable that happens to be initialized by the compiler in debug builds, but isn't in release.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.