Archived

This topic is now archived and is closed to further replies.

AcoGL

Assertion Failure

Recommended Posts

AcoGL    122
Please help me. I have programming problem. When I Execute program in Visual C++ 6.0 a message box appears: ASSERTION FAILURE. And when I Debug(F5) it works fine. There are no errors. How can I find out where the problem is??? It''s urgent. Please reply if you heve any idea. Thanks.

Share this post


Link to post
Share on other sites
simba    122
sounds like an uninitialized variable. In debug(F5) the compiler will initialize variables to some value for you in release mode they won''t. This is assuming when you say "When I execute the program" you mean you''re executing a release build. Make sure everything is initialized.

Share this post


Link to post
Share on other sites
AcoGL    122
Finally I have found what''s going on.

I allocate dynamic memory (new) for 2 variables. And then when I change values of one there is change of values of the second one. But "funny" is that this happen during executing release version. While debuging, everything works fine.

This is weard to me.
Do you have any ide why this happen???

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
in debug builds code is not optimized, which means there can be plenty of unused space between variables and functions. If you somewhere happen to write outside an array or do some other write to memory that is not allocated for you, it''s likely that you write into that unused memory. It''s of course not valid, but probably it will not cause a crash.

In release builds however, everything is packed together, so if you''re writing outside a buffer, you will most likely overwrite something else, which is more likely to crash.

The bug is there in both debug and reiease builds, but not as visibile in debug builds.

Share this post


Link to post
Share on other sites
AcoGL    122
If anyone has an idea how to avoid this problems, please reply. I have seen many good guys at this forum.

P.S.: Thanks a lot to all who replayed my topics.

Share this post


Link to post
Share on other sites
Lazzar    127
post your code if its not too big and we can see where your problem lies.

If you cant find the error in Debug mode, you could use printf''s to pseudo debug your programm in release version, so you can see about where you get the error.

like:
printf("start")
printf("now i do this...")
printf("now i do that...")
printf("plValue is: %d", *plValue)
etc...

and check your pointers again.

good Luck
Lazzar

Share this post


Link to post
Share on other sites
AcoGL    122
This is really good idea, Lazzar. It helped me to solve my problem. By doing this I have found the point in my code where it fails somehow and I have avoided the bug.

I will not post the code, because it is very long and complex (for me :-), but thanks a lot for your advices, guys.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I would indeed recommend running this under a debugger! There''s no reason why you shouldn''t treat the debugger as your favourite friend when running into similar problems.

As I understand, your problem was visible only in release builds. In your case with vc++ 6.0, make sure to enable debug symbols in release builds and run the program under the debugger. I recommend to always "break on exceptions", in vc++ 6.0 it''s a setting in the debug menu that appears once you''re debugging something if I rememeber correctly.

printf might work as an extra ain, but I cannot se why you shouldn''t use the debugger instead?!?!? Using printf as debugging aid has been a pain for Java developers until about now when the first standardization of debugging interfaces has been set. Microsoft has had this all the time both in managed and unmanaged code - use it!

http://www.cygnus-software.com/papers/release_debugging.html
http://www.amazon.com/exec/obidos/tg/detail/-/0735615365/qid=1074428778/sr=1-1/ref=sr_1_1/002-6262703-7558442?v=glance&s=books

Share this post


Link to post
Share on other sites