Player Pointer invalid.

Posted By: Jethro

Player Pointer invalid. - 06/18/08 23:51

This is not a gremlin, and has occurred since upgrading to A7 The same code that worked with A6.314 doesn't work with A7.
I have reported this before but it was dismissed as a gremlin.

I have more info now so hopefully someone will look into it.

I am a PRO user and have been since A3.9 15 published games with gamestudio 10's of thousands of games sold. (My credentials over with.)

OK. This fault exists with A7.07 and current Beta A7.08 as well.

I have over 35 Include files in our main WDL file.
Near the end of one of these files after about line 7500 of code the player pointer is no longer seen!.

Every new function we add with
While (Player==NULL) {Wait(1);}
Never gets past this line of code whilst other function in other includes and before line 7500 (approx) in this include do!
So the player pointer is definately getting set this is the first thing we do in any of our player code!
To Work around this problem we ALSO set a new pointer called my_player. When we evaluate this with
While (MY_Player==NULL) {Wait(1);} our code now works.
The main reason I think it is a bug is everything worked OK with A6.
Its not just the above line of code either its anything to do with the player pointer.
eg. If Vec_Dist(my.x,Player.x)>100 will give an invalid pointer error even after the Player pointer is defined.

I've also noticed that WED repeats Actions in the action list when selecting an action for an Entity.
It seems to pickup the pre-defined function names as well.

Jethro.
Posted By: jcl

Re: Player Pointer invalid. - 06/19/08 05:40

The first thing to do in such cases is debugging. Anything could be an engine bug, but you'll never know unless you look where the problem lies at all. I can help when I know where the problem happens, and under which circumstances.

"Invalid pointer" means that a pointer is NULL. The first thing to do is finding when and where in the code that pointer is set to NULL. Display the pointer on the screen, like this:

draw_text(str_for_num(NULL,player),10,10,vector(0,0,0))

and check if and when "player" changes.
Posted By: Jethro

Re: Player Pointer invalid. - 06/20/08 00:42

OK. I implemented what you said in two areas of my code,and this verifies what I already know.

The following code is in the faulty entities action.
While (Player==Null){
draw_text(str_for_num(NULL,player),10,50,vector(0,0,0));
Wait(1);
}
The above always returns "0".

The following code is in the players main loop
while(1) {
draw_text(str_for_num(NULL,player),10,10,vector(0,0,0));
move_view();
....rest of code
wait(1);
}

The above always returns "39965.617".
So the constant screen display is

"39965.617" --> player function using "player" pointer
"0" --> Entity function using "player" pointer

This prooves that in one area of my code the Engine defined Player pointer is set and in another area of my code it isn't.

OK. To my workaround.

Where I set the player pointer, I also set an extra player pointer, "my_player" as follows.

Player=me;
MY_Player=me; //Set this because of invalid Player pointer bug!

Now when I monitor the MY_Player pointer, in the same entity function it is recognised as valid and falls throuigh to the following loop which constantly displays the same pointer number as "Player" Pointer.
Entity code snippet.
While (vec_dist(my.x,MY_player.x) > 50) {
draw_text(str_for_num(NULL,MY_player),10,50,vector(0,0,0));
Wait(1);
}

So the constant screen display is

"39965.617" --> player function using "player" pointer
"39965.617" --> Entity function using "my_player" pointer


Go Figure "my_player" is reliable but "player" is NOT recognised from within this entities ACTION!
In all but one other "Faulty" entity function. The Player Pointer is recognised!

I know this doesn't make any sence at all that is why I'm reporting it!

Hope this helps jethro.

Heres the entire faulty action unedited.

Action SCTur_PU {
//first reset the counters.
MY.Passable=on;
MY.Invisible=on;
Sub_Stage=1; //This is the eggs and turtle picked up
Sub_level=1; //This is the secpan
If (Main_Diff==1)&&(My.Flag1==0){ent_Remove(me);}
If (Main_Diff==2)&&(My.Flag2==0){ent_Remove(me);}
If (Main_Diff==3)&&(My.Flag3==0){ent_Remove(me);}
//I'm for this difficulty so wait until Im needed
While (MY_Player==Null){draw_text(str_for_num(NULL,MY_player),10,50,vector(0,0,0));Wait(1);}
While (MY.Skill1!=Sub_level){Wait(1);}
//I'm now active, so wait to get picked up.
Turtle_Ent=ME; //So GPS Can find me
//MY.Passable=off; //not sure if turn this off. definately need on to carry turtle
MY.Invisible=off;
//Do it with proximity
While (vec_dist(my.x,MY_player.x) > 50) {draw_text(str_for_num(NULL,MY_player),10,50,vector(0,0,0));wait(1);} //For now just wait for player
//We're picked up from here, lock me to player.
Got_turtle=My.skill1;
While (Got_Turtle!=0){// Lock me to player
vec_for_vertex(temp,MY_Player,56);//Read Top left corner vertex
vec_set(my.x,temp.X);
vec_set(My.pan,MY_Player.pan);
Wait(1);
}
//Now get dropped off at secpan, and trigger the secpan.
Ent_Remove(me); //Im Removed while they do the sec pan.
}
Posted By: jcl

Re: Player Pointer invalid. - 06/20/08 05:43

The action you posted contains an obvious bug in this line:

If (Main_Diff==3)&&(My.Flag3==0){ent_Remove(me);}

You have to terminate the action here. You must not use the 'me' or 'my' pointer anymore after removing the entity.

I don't know if that can be the reason of the player pointer problem. If you can't find the reason, I suggest that you strip down the level so that is just shows the problem, and then send it to me - I'll look into it.
Posted By: Jethro

Re: Player Pointer invalid. - 06/20/08 13:39

Yeah sorry for that, we just implemented this and hadn't tested with the diff2 and 3 entities, its not the reason, we corrected that already.

It should read:-
If (Main_Diff==3)&&(My.Flag3==0){ent_Remove(me);Return;}

I can't find the bug, I'll try to strip down, however it's not going to be easy! I suspect stripping down, may clear the bug, if it's to do with the size of the scripts.

Jethro
Posted By: fastlane69

Re: Player Pointer invalid. - 06/20/08 14:15

Don't strip your code, merely create a stand-alone application (a stub) that specifically and exclusively tests out the "player" pointer. It would take very few lines and would resolve this question neatly.

After all, if the problem is with the engine, a few lines using the Player pointer will amplify that bug and make it MUCH more efficiently to squash than searching through actual code. And if the problem is not with the engine, then the stub will run as normal and the problem lies elsewhere.
Posted By: Jethro

Re: Player Pointer invalid. - 06/23/08 01:08

You make it sound so simple, Even if I make a 1 level application with our code base it needs about 80mb of predefined stuff, which is a bit difficult to email to support.

There is no simple fix, other than spend some time to commonise all references to sounds bitmaps etc, so the script doesn't break when you run it.

Jethro.
Posted By: fastlane69

Re: Player Pointer invalid. - 06/23/08 01:10

But it is that simple. cool

You're missing the point. A stub would have minimal graphics and everything... it's only purpose is to test your hypothesis: is player pointer broken? It shouldn't take more than an hour to write and test several whiles and ifs and other commmands using player... and then you know if the problem is with the engine or your code.

It's that simple. One hour. Tops.
Posted By: jcl

Re: Player Pointer invalid. - 06/23/08 08:23

The problem is that when creating a special application for testing the player pointer, you probably can't reproduce such a problem that is specific to a certain project.

Stripping down the project on the other hand has the advantage that in the process of stripping down, you have a good chance to find the reason of the problem at some point. Remove functions step by step and always test if the last step fixed the bug.
Posted By: fastlane69

Re: Player Pointer invalid. - 06/23/08 20:58

Absolutely, JCL. My point is merely towards the "engine bug vs. code bug" debate.

If it's agreed that a code bug (as we all suspect), then yeah, obviously stripping is the way to go. But if you still harbor any question that it could be the engine, then a stand alone app is the only way to go.
Posted By: Jethro

Re: Player Pointer invalid. - 06/23/08 23:16

Fastlane is missing the point, it's obviously not an OBVIOUS engine bug or more people would have this problem. So a simple stub won't reproduce the problem.

Even though my rating is Juniour Member(I'm 48). I've been on and off Beta programs sincs A3.9 and reported many real bugs, we've pushed the envelope of this engine in many ways.

If its a code bug, Why did this specific bug show up when converting to A7. The function in question didn't even change!First time I seen this bug is when I converted a project from A6.314 to A7, It was as if The player pointer didn't exist anymore in this area of script. Now when I add new functions below this function they are broken also. However other files included after this are not.

JCL Can it be a script size problem?

Just to test, I'm going to break the suspect script into 2 scripts. I'll see how this goes.

Jethro.
Posted By: Jethro

Re: Player Pointer invalid. - 06/24/08 00:14

OK Here's some more info.

I chopped the faulty functions off the end of the faulty script and pasted them into a new script, I included the new script straight after the one it was in, so structurally the code would get loaded the same.
The fault still existed.

Here's the clue JCL, now I have this faulty piece of code (there's actually nothing wrong with the code) in a separate script, I can change its position (within reason, to save changing other code).

I moved it down further in the includes so It's actually closer to the code that sets the player pointer.

It now works perfectly.

There were absolutely no mods to the code except change my workaround pointer "my_Player" back to the faulty "player" pointer to test.

Now another test, when I move the script further away from the
end of the script, (ie. closer to the top of the includes.) the pointer becomes invalid again!!

So in a nutshell the faulty pointer becomes valid again simply by moving the functions closer to the end of the loaded script.

I hope this provides some more clues.

Jethro.
Posted By: jcl

Re: Player Pointer invalid. - 06/24/08 08:50

Yes, it indeed does. The position of functions in the code determines their order in the scheduler list. From your description I would also expect a dependence of this kind. Something sets the player pointer back, but this has only an effect if it either happens after the pointer is set, or before it is evaluated.

So the critical function that resets the player pointer is either somewhere within the code part that you moved. Or it is immediately before or behind the position where the inserted code just worked again.
Posted By: Jethro

Re: Player Pointer invalid. - 06/25/08 01:02

I Found the bug.
I moved the problem include, 1 position down in the list of includes 1 at a time, until it started to work.
Then I went over the last include I leapfrogged, mymove3_c.wdl, with a fine tooth comb.

I'm now Eating a heafty chunk of humble pie.
In my code the Player pointer had been re-defined with:-
Entity* player;

I take most of the blame, however the old templates are what caused it in the first place.
Now because my code is converted from version to version, this has snuck in from the old A5 templates where the conitec template code actually reads:-
//SYNONYM player { TYPE ENTITY; }
//SYNONYM temp_ent { TYPE ENTITY; }
//SYNONYM carry { TYPE ACTION; }
entity* player; // pointer to player entity
entity* temp_ent;
action* carry;
inside movement.wdl!

Obviously re-defining the player pointer will cause mass confusion to the same pointer references before this, in A7, however it must have been a requirement in A5?
I was certain it was something to do with the engine because it only happenned after the A7 upgrade.

Thankyou very much JCL, for your help with this, sorry for wasting your time.

I had searched player== player= etc. across all files, however my editors search doesn't allow * char to find pointers.

You can safely remove this from the Bug list now.

Thanks again Jethro.
Posted By: fastlane69

Re: Player Pointer invalid. - 06/25/08 02:22

Quote:
Fastlane is missing the point, it's obviously not an OBVIOUS engine bug or more people would have this problem. So a simple stub won't reproduce the problem.


Can I bring the Ice Cream and we'll make it Humble Pie a-la-mode? Much sweeter that way. laugh
© 2023 lite-C Forums