6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood),
1,268
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Pointer-pointer not valid after frame
#248428
01/26/09 20:25
01/26/09 20:25
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
OP
Expert
|
OP
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
typedef struct {
int value;
} PTR;
void processPointer( PTR **p ) {
wait(1); //the wait causes **p to be invalid
*p = (PTR*)malloc(sizeof( PTR ));
(*p)->value = 1;
}
void main() {
PTR* p = NULL;
processPointer( &p );
while( !p ) {
draw_text("Still in while loop...", 10, 10, vector(255, 255, 50));
wait(1);
}
error("check!");
}
As stated, the wait(1); in processPointer() makes the **p pointer become invalid somehow. At least, the error("check!"); is never called when the processPointer() function waits one frame. If I comment out the wait, the "check!" error pops up as expected. I can't see any reason why this would happen further than that waiting a frame screws up...
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: Pointer-pointer not valid after frame
[Re: jcl]
#248684
01/28/09 15:22
01/28/09 15:22
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
OP
Expert
|
OP
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
That's great, it seems to work, and it does make sense . Thanks alot for the answer.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: Pointer-pointer not valid after frame
[Re: Joey]
#248709
01/28/09 18:48
01/28/09 18:48
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
The address becomes invalid because when the stack restores all the stacked variables, they dont necessarily end up in the same position in memory as they were before, which means their address has changed. Therefore, addresses become invalid, but pointers are fine because they are pointing to another variable, not its actual address.
That how I understand it anyway.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|