Ok so I've made a little game using SDL but when I try to 'destroy enemies' in a radius of my character I try to remove the x and y coordinates of the 'enemies' from their respective vectors. When I run it the 'enemies' are removed/it works but the program then closes and the terminal returns 'Segmentation Fault'. Why is this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void ship_fire() {
if (bombs_away){ //If spacebar is pressed
int proximity;
for (int j=0; j<n_enemy; j++) {
proximity = sqrt(pow(x_enemy[j]-a,2.0) + pow(y_enemy[j]-b,2.0));
if (proximity <=50) {
x_enemy[j] = x_enemy.back();
x_enemy.pop_back();
y_enemy[j] = y_enemy.back();
y_enemy.pop_back();
}
}
}
}