What could cause assertion failures

Started by
6 comments, last by phresnel 15 years, 3 months ago
Im currently busy coding a small computer game simmilar to a space invaders type game. but when the player fires a bullet and it hits the top of the screen(Thats when the sprite must be killed), the programme crashes and gives me an assertion failure message? I cant seem to find why the game is doing that. So what could be causing this? Please help!
Advertisement
Quote:Original post by _damN_
Im currently busy coding a small computer game simmilar to a space invaders type game. but when the player fires a bullet and it hits the top of the screen(Thats when the sprite must be killed), the programme crashes and gives me an assertion failure message? I cant seem to find why the game is doing that. So what could be causing this?

Please help!
It could be any one of a million things.

What does your Debugger tell you?
What is the assertation failure message, if any?
The debugger doesnt say anything... The game runs. I just thought that there was a general reason for an assertion error to accur?!

Its when a bullet collides with the edge of the screen.

It could be something like trying to dereference a NULL pointer (i.e. the bullet was removed, it's pointer set to NULL, but it's used elsewhere as well -- some place that checks for NULL pointer using an assert) or that perhaps you're drawing outside the screen and there's an assertion that checks whether you're drawing within bounds...

Generally, assertions are used to check for invalid input parameters to a function. If you're not doing that yourself, then it is in a library you're using. The most common cause for such things is memory corruption.

You're going to have to give some more information if you want more than general hints.
Kippesoep
Quote:Original post by _damN_
The debugger doesnt say anything... The game runs. I just thought that there was a general reason for an assertion error to accur?!

Its when a bullet collides with the edge of the screen.
When you get the assertion, the debugger will break on the line that's causing it. You can then look up the call stack into your code and examine the contents of the variables to find out why the error occurs.
Every tutorial site should make their second tutorial (after Hello World) a "basics of debugging" tutorial. Debugging is one part of programming that is pretty well completely ignored in academia (from a teaching standpoint anyways). I'm pretty sure I used to debug using printf statements when I was in my first year of university.
Also, you intially said you get an "assertion failure message" (sic). So, what exactly is this message?

This topic is closed to new replies.

Advertisement