c++ - VS2015 vector iterator not dereferencable -
i have little problem, have build 2d game based on sdl.
i keep getting errror when try delete 2 objects colliding in "scene".
std::vector<waspobject*>::iterator itw; std::vector<projectileobject*>::iterator itp; (itp = _projectiles.begin(); itp != _projectiles.end();) { (itw = _wasps.begin(); itw != _wasps.end();) { if ((*itw)->get_positiony() + 37 >= (*itp)->get_positiony() + 0 && (*itp)->get_positionx()+0 >= (*itw)->get_positionx()+0 && (*itp)->get_positionx()+0 <= (*itw)->get_positionx()+49) { itw = _wasps.erase(itw); itp = _projectiles.erase(itp); } else { itw++; itp++; } } }
_wasps , _projectiles std vectors in scene.
can me find problem? in advance!
if don't hits , increment itp
in inner loop, might run past _projectiles.end()
.
for example if there more wasps projectiles. or if on last projectile, reach _projectiles.end()
after single itp++
.
so might want test both end conditions @ each turn of inner loop.
Comments
Post a Comment