|
Entity pointer passed to function
#344222
10/15/10 09:36
10/15/10 09:36
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
We can't seem to figure this one out, though I guess the answer is prett simple. The below code should - in my oppinion - stop counting up my_temp[0] as soon as "t" is pressed. When t is pressed, the entity counter in the F11 debug panel is set back to 0, so the entity IS removed. Still, the function which I passed the entity to keeps running. I don't understand why I can manipulate inLight fine (inLight.x += time_step; for example) but inLight != NULL never returns 0, even when the entity does no longer exist. Funny thing: my_temp[0] gets reset to 0 when I press t, but then keeps counting up. it's like the real entity is removed but replaced by some fake entity so the function can keep running?
var my_temp[9];
FONT* fallbackFont = "Arial#12b"; // truetype font
PANEL* deb_pan = {
pos_x = 20;
pos_y = 300;
layer = 1200;
digits = 0,12,8.4,fallbackFont,1,my_temp[0];
}
void runWhileEntity(ENTITY* inLight)
{
while(inLight != NULL)
{
inLight.x += time_step;
my_temp[0] = inLight.x;
}
beep();
beep();
beep();
}
void main()
{
set(deb_pan,SHOW);
level_load(NULL);
wait(3);
ENTITY* theEnt;
theEnt = ent_create(NULL,nullvector,NULL);
runWhileEntity(theEnt);
while(key_t == OFF) wait(1);
ent_remove(theEnt);
}
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Entity pointer passed to function
[Re: Germanunkol]
#344224
10/15/10 09:42
10/15/10 09:42
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Although you remove the ENTITY, the pointer still points to the memory area where the entity was. It doesn't gets set to NULL because you never set it to NULL.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Entity pointer passed to function
[Re: WretchedSid]
#344231
10/15/10 11:00
10/15/10 11:00
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Well, ent_remove(theEnt); theEnt = NULL; doesn't work either, because it's not the same pointer. So how do I set ENTITY* inLight to null? from outside the function? I can't, right? cause the scope of that variable's limited to the function...?
Last edited by Germanunkol; 10/15/10 11:00.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Entity pointer passed to function
[Re: Germanunkol]
#344232
10/15/10 11:24
10/15/10 11:24
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
You can pass a pointer to a pointer like this:
void runWhileEntity(ENTITY** inLight)
{
while(*inLight != NULL)
{
*inLight.x += time_step;
my_temp[0] = *inLight.x;
}
beep();
beep();
beep();
}
void main()
{
set(deb_pan,SHOW);
level_load(NULL);
wait(3);
ENTITY* theEnt;
theEnt = ent_create(NULL,nullvector,NULL);
runWhileEntity(&theEnt);
while(key_t == OFF) wait(1);
ent_remove(theEnt);
theEnt = NULL;
}
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Entity pointer passed to function
[Re: WretchedSid]
#344233
10/15/10 11:33
10/15/10 11:33
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
use fuction as the action of the entity and use a while-me loop instead?
3333333333
|
|
|
Re: Entity pointer passed to function
[Re: Bunsen]
#344308
10/16/10 06:54
10/16/10 06:54
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
The pointer of pointer method is not working here (although ok in other multitasking systems) because in Lite-C on reentry the stack is not originally reconstructed. Wow, thanks for the info!
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Entity pointer passed to function
[Re: Bunsen]
#344309
10/16/10 07:29
10/16/10 07:29
|
Joined: Jan 2003
Posts: 4,615 Cambridge
Joey
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
The pointer of pointer method is not working here (although ok in other multitasking systems) because in Lite-C on reentry the stack is not originally reconstructed. honestly? why is that? and what has it to do with the stack? that would be extremely counter-intuitive if you could pass pointers to the heap and not to the stack. i thought that would be the whole point in the coroutine stuff. so basically what you're saying is that *inLight is not guaranteed to be theEnt anymore?
|
|
|
Re: Entity pointer passed to function
[Re: Joey]
#344326
10/16/10 13:38
10/16/10 13:38
|
Joined: Dec 2008
Posts: 271
Saturnus
Member
|
Member
Joined: Dec 2008
Posts: 271
|
|
|
|
|