Skip to main content
gamedev.net
🔒 Locked

vector problem

Started by xg0blin 0 replies 200+ views
Original Post
xg0blin
xg0blin
ok, here''s the deal. I''m making a game of breakout. It works well except for one little bug that''s crashing the program. I use a vector of TexQuad''s (just a struct to read in textured quads from a file). When I collide with a block, I reflect the ball and then do a level->area.erase(); by the way, my level struct is a vector area. As I read the TexQuads in, I push_back onto the vector. Again, when I collide, I erase the quad. It works perfectly, except for when the very last item in my vector gets deleted, it crashes the whole thing. It doesn''t matter if the other blocks are still there or not, just when the last block in the vector gets deleted, the program crashes. So, basically, anytime I am playing, and I collide with the top-left block, my program crashes. It works with any other block. I even tried to do a check to see if it was the last block in my vector, and if it was to do a pop_back, otherwise just erase. I looked through my program and tried to figure if I was trying to use that item anywhere after that point, and I am not. I''ve debugged and debugged and debugged some more, but it''s not real easy when you have to collide with a certain block to get it to crash. I know it''s in my vector class, cause when the little assertion window pops up informing me I have crashed the program, and I go to debug, it takes me to vector.h. Anyone know why this might be happening?
xg0blin
xg0blin
Ok, nevermind, I got it. I used a num_blocks that was equal to level->area.size() before the for loop to save on dereferencing calls. When I lost a block, I didn''t decrement the number of blocks. It is fixed.

Topic Locked

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

Sign in to reply to this topic.