I get crashes implying that I have an invalid pointer when I go through the list with ent_next after removal of an entity. The easiest way to trigger it is to continously spawn and remove entities. Here's a bit of code that runs without assets that crashes it. Run it, then hold SPACE to start and run the ent_next-loop. Crashes when it hits the str_for_entfile-instruction.
function exploeffect() {
wait(3);
ent_remove(me);
//ptr_remove(me); //those make no difference
//safe_remove(me);
}
void showall() {
VECTOR t;
while(key_space) {
you = ent_next(NULL);
while(you!=NULL) {
vec_set(t,your.x);
vec_to_screen(t,camera);
draw_text(str_for_entfile(NULL,you),t.x,t.y,COLOR_RED);
// draw_text(you->type,t.x,t.y,COLOR_RED);
you = ent_next(you);
}
wait(1);
}
}
void main() {
VECTOR temp;
level_load("");
wait(3);
on_space = showall;
VECTOR temp;
while(1) {
vec_set(temp,vector(200+random(100),random(100)-50,random(100)-50));
ent_create(CUBE_MDL,temp,exploeffect);
wait(-0.3+random(0.5));
}
}
Interestingly, it does NOT crash when you replace str_for_entfile with you->type. (the line's up there - but commented out - if you want to try).
However, it's not just str_for_entfile that crashes. You could replace it with, say
c_move(you,vector(1,0,0),nullvector,IGNORE_YOU);
to get it to crash. Or with
ent_animate(you,"",total_ticks,0);
What I'm saying is, the pointer seems to be invalid. So...
Why do I get invalid pointers (from removed entities?)
from ent_next?