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

assert in release

Started by luasitdown Jan 20, 2006 at 8:32 AM 2 replies 600+ views
Original Post
luasitdown
luasitdown
How to do assert in release? or something similar? BTW assert(dosomething() ); it is bug, because it will be remove in release. so dosomething() never is call . problem occur in translate from debug to release, I put here for warnning. Are there something else that need to pay attention to in debug to release?
Samurai Jack
Samurai Jack
Asserts are ment to check some things in debug and NOT IN RELEASE.

Usual someone uses ASSERTS to check if pointers are vaild, if file handles are open, if string sizes are greater than zero and so on.

Asserts help you to control your program, but they also make it slower. Usual someone makes asserts there, where it is critical that a condition is true and for usual it should newer happen.

for example a simle render loop

create device and get a pointer for pMyDevice...
if (pMyDevice == NULL) go out

further more somewhere in program
while(TRUE)
{
assert(pMyDevice != NULL); //you do not need that in RELEASE
pMyDevice->BeginScene();
..render stuff
pMyDevice->EndScene();
}

Asserts are JUST FOR CHECKUP NOT to be used ANYWHERE IN PROGRAM AS POSSIBLE.
frob
frob
Asserts are just there to help in debugging.

Even so, it isn't unusual to see something like this:
bool foo( void* x ) {  assert( x != 0 && "We can't compute the foo of a void pointer." );  if( 0 == x )    return false;  ...

(Oh, and in case you didn't know about it, you can add 'comments' to assert statements just like I did above to display when the program stops.)

The above command will use the assertion in debug builds, tripping the debugger or otherwise killing the program. In release builds, it will return false since that's the safe way to proceed.
HaywireGuy
HaywireGuy
ASSERT(DoSomething());

In this case DoSomething() will not be executed in Release build. Try one of these options instead:


if(!VERIFY(DoSomething()))
return false;

or


bool bResult = DoSomething();
ASSERT(bResult);
if (bResult)
return false;


"VERIFY" is the same as ASSERT, the only difference is that it evaluates the statement also for Release build (without popping up message boxes). As Jack said assertion statements are meant to catch careless mistakes made in Debug build, these assertions should never be fired even if they are in Release build.

Topic Locked

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

Sign in to reply to this topic.