3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
ent_next bug with removed entities?
#449690
03/29/15 00:41
03/29/15 00:41
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
OP
Expert
Joined: Jul 2002
Posts: 3,208
Germany
|
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?
Perhaps this post will get me points for originality at least.
Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
|
|
|
Re: ent_next bug with removed entities?
[Re: Error014]
#449705
03/29/15 15:59
03/29/15 15:59
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
If you run this modified code
var new_counter = 0;
void exploeffect()
{
my.skill1 = 123;
wait(3);
my.skill1 = -123;
ptr_remove(me);
}
void main()
{
VECTOR temp;
level_load("");
wait(3);
while(1)
{
new_counter -= time_step;
if(new_counter <= 0)
{
new_counter = random(5);
vec_set(temp,vector(200+random(100),random(100)-50,random(100)-50));
you = ent_create(CUBE_MDL,temp,exploeffect);
if(your.skill1 != 123 || 1) printf("ohh (%d)",(int)your.skill1);
}
for(you = ent_next(NULL); you != NULL; you = ent_next(you))
{
if(your.skill1 != 123) printf("hm (%d)",(int)your.skill1);
vec_set(temp,your.x);
if(vec_to_screen(temp,camera)) draw_text(str_for_entfile(NULL,you),temp.x,temp.y,COLOR_RED);
}
wait(1);
}
}
you will see that you get three "ohhs" before the first "hm" appears, correlating to the wait(3) in the exploeffect function. I don't know why though, so sorry for not being able to help at all. :< EDIT: Oh and the "hm" error message shows a skill value of 0, not -123 as I would have expected.
Last edited by Superku; 03/29/15 16:00.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: ent_next bug with removed entities?
[Re: Superku]
#449725
03/30/15 11:05
03/30/15 11:05
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
function exploeffect()
{
wait(3);//<--- works now
//wait(-3)//<--- works if you replace the wait(1) in the main loop with the old wait(random thingy)
if(me)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));//<--- posible wait issue here
wait(1);//<--- works with this wait here
}
}
some sort of complicated wait problem ,because wait returns back to the calling functions i suppose
Compulsive compiler
|
|
|
Re: ent_next bug with removed entities?
[Re: Wjbender]
#449726
03/30/15 11:45
03/30/15 11:45
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
also if you synchronized the wait value in explodeffect and the main loop wait value , it works , the timing at which things happen overun at the wrong times ?
quite strange
Compulsive compiler
|
|
|
Re: ent_next bug with removed entities?
[Re: Wjbender]
#449738
03/30/15 16:52
03/30/15 16:52
|
Joined: Jul 2000
Posts: 27,986 Frankfurt
jcl
Chief Engineer
|
Chief Engineer
Joined: Jul 2000
Posts: 27,986
Frankfurt
|
I can not see why you should get a crash in your script. You'll get an error message though: in development mode, the engine detects that you try to display the name of a removed entity. The release version would just display nothing. If you remove an entity, it's still in the entity list, it just is not visible anymore and has no name or other properties. It only gets physically removed from the list at the next garbage collection, which happens at the end of every cycle. So the easy solution is to check if the entity has still a name:
while(you!=NULL) {
if(you->type == NULL) break;
...
Hope this explains the problem.
|
|
|
Re: ent_next bug with removed entities?
[Re: jcl]
#449742
03/30/15 17:09
03/30/15 17:09
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
so we have to check entities with !=null and type!=null , to be sure we dont use a entity pointer with no data , instead of just !=null ALWAYS ?
or just with the list ?
Compulsive compiler
|
|
|
Re: ent_next bug with removed entities?
[Re: Wjbender]
#449776
03/31/15 09:24
03/31/15 09:24
|
Joined: Jul 2000
Posts: 27,986 Frankfurt
jcl
Chief Engineer
|
Chief Engineer
Joined: Jul 2000
Posts: 27,986
Frankfurt
|
No, it is not related just to the list, but can also happen in other circumstances. When you have two different actions running on the same entity, and the first action removes the entity at some point, the second action must test the used entity properties - name, position and so on - in order to detect if the entity is still there. Removed entities have no name, no flags, position is zero, and also all other entity properties are nonexistent or zero.
|
|
|
Re: ent_next bug with removed entities?
[Re: jcl]
#449778
03/31/15 09:58
03/31/15 09:58
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
thank you jcl
@ error014 wow thanks for finding this !
I am going to write a function or something I can always call when I need to check , this is new for me.
Compulsive compiler
|
|
|
Re: ent_next bug with removed entities?
[Re: Wjbender]
#449880
04/01/15 20:33
04/01/15 20:33
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
OP
Expert
Joined: Jul 2002
Posts: 3,208
Germany
|
Thank you jcl for the reply and the details! And apologies for saying "crash" when it wasn't a crash - I guess I use the term too liberately Anyhow, I think that this:
If you remove an entity, it's still in the entity list, it just is not visible anymore and has no name or other properties. It only gets physically removed from the list at the next garbage collection, which happens at the end of every cycle.
So the easy solution is to check if the entity has still a name:
Should definitely be in the manual under "ent_next". I sure hope you'd agree that for someone not knowing the details of the engine, this isn't apparent otherwise. Same goes for this: No, it is not related just to the list, but can also happen in other circumstances. When you have two different actions running on the same entity, and the first action removes the entity at some point, the second action must test the used entity properties - name, position and so on - in order to detect if the entity is still there. Removed entities have no name, no flags, position is zero, and also all other entity properties are nonexistent or zero.
Which I think should be under "ent_remove" in the manual. Thanks again! And also big thanks to you two Superku and Wjbender! Good to see I wasn't crazy
Perhaps this post will get me points for originality at least.
Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
|
|
|
|