Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

assert in release

This topic is 4653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!