Player Entity pointer is sometimes NULL after setting.

Posted By: Jethro

Player Entity pointer is sometimes NULL after setting. - 05/22/08 13:18

A7.07 Pro.
Heres another weird problem after upgrading from A6.314 to A7.07, this fault is also in A6.60.

In 2 functions in my code, the Engine defined Player Pointer is NULL even after it is set with Player = ME in our main player movement routine.
In many other functions in the code Player is infact set to a valid entity, and lets my code past the
While (Player==NULL) {Wait(1);} varification loop.

So to fix the broken functions, I use MY_Player=ME; and PLAYER=ME; to set the pointer, and use
While (MY_Player==NULL) {Wait(1);} to wait until it is set
if vec_dist(my.x,MY_player.x)<200 etc.....
This all works fine, what could be reason for flakey Player pointer.

Jethro ...
Posted By: jcl

Re: Player Entity pointer is sometimes NULL after setting. - 05/22/08 14:16

If I understood you right, the player pointer in your code was NULL and you solved this by setting it. This is certainly a correct and valid solution, however I'm not sure why you're posting this in "bugs" - what can we do to help?

Even if it might sometimes seem that goblins are changing pointers behind your back ;), I can assure you that pointers only get changed when you set them or when something happens to the object they point to. But if you have problems with an entity pointer in your code, just use the 'watched' variable for observing it.
Posted By: Jethro

Re: Player Entity pointer is sometimes NULL after setting. - 05/23/08 00:22

Sorry there must be a communications breakdown.

1 - I set Player = ME in main movement routine for player!
2 - Many functions in the game recognise this, 500 enemies are happy that the player pointer is set. Every tick these guys are doing a vec_dist with the player pointer with no problems.
3 - Another function DOES NOT get past the
While (Player==NULL) {Wait(1);}

The fix to this was make a new Entity Pointer MY_Player and monitor for that in the broken function with:-
While (My_Player==NULL) {wait(1);}
Continue here ....

I have been using this engine since A3.9 have 15 published games, this is my full time occupation, and I don't believe in goblins. I have developed an in game editor, 3d Text routines and games of every description with this brilliant engine.

In a nutshell there are a 2 functions since converting to A7.07 from A6.314, that simply don't see the correct status of the player Pointer. Note A6.6 also exhibits this anomoly, not sure about A6.4.

Our code base is huge with 40 included code files (.wdl) some of these files have over 8000 lines of code.
Could I have overflowed something?

The weird thing is this problem was NON EXISTANT IN A6.314!

Jethro.
Posted By: Tobias

Re: Player Entity pointer is sometimes NULL after setting. - 05/24/08 09:40

The player pointer is a global pointer and global pointers can not be NULL for one function and non NULL for another, because they are either NULL for all functions, or non NULL for all functions.

As a programmer I know the problem with the goblins and this sounds like one. Such problems always turn out to be a missing semicolon or setting something at the wrong moment or a = instead of == or the like. I think you can easily find out whats happening when you put a breakpoint in the function that does not get the player pointer correctly, and debug it single step wise.


Posted By: Christian__A

Re: Player Entity pointer is sometimes NULL after setting. - 05/24/08 12:24

Search for all "player =" or "player=" in your code. I'm sure you will find a line in which you typed if (player=XYZ) instead of if (player==), as tobias said.
Posted By: ARAS

Re: Player Entity pointer is sometimes NULL after setting. - 05/24/08 14:21

Hello Jethro,

i also have this problem. But i fixed it.

In your main-wdl you must first include the wdl-script with the "player = me" action.
And than include the other wdl-scripts with the "while(player==NULL)" loops.

Sometimes it helps.

MFG

aras
Posted By: coma_dose

Re: Player Entity pointer is sometimes NULL after setting. - 05/26/08 19:17

I had a strange experience with a pointer, let's see if this occurance belongs in the bug hunt section:

An entity action was referring to itself using "my" like so.

Code:
while(me)
{
   my.pan -= 90;
   wait(1);
}


I start the game and I get an empty pointer error. Eh? So what I did was I inserted a beep; before and after the loop, and one at the beginning for good measure. Upon restarting the test run, I got two beeps; one at the beginning and one right before the loop, the third beep did not occur because the loop was running and therefore, "my" was a valid pointer. Needless to say I also got the empty pointer error as well.

How can a "while(me)" loop be running and at the same time the "my" pointer be empty, within an action assigned to an entity? There were no other bits of code setting "me" to null and the entity was not being removed. I clicked "OK" and continued to see my entity on screen, the FPS was seriously hit as usual when you "OK" past a script error on a test run.

How did I resolve this? I didn't; I removed the beep; functions and tested again and it worked fine.

Last question: How can the beep; function be the cause of an empty "my" pointer when the error occured before (and after, meaning it had its origins elsewhere)I placed the beep; function in the action? This was the most strange A7 goblin that I have ever seen.
© 2024 lite-C Forums