Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AbrahamR), 717 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Empty pointer? (Solved) #409107
10/11/12 18:59
10/11/12 18:59
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
Hi,
I'm having trouble with entity pointers, which leads to an error stating that I have an empty pointer and it prevents my AI opponents from working properly. I do try to filter out empty pointers by using a simple if-statement, but it still seems to slip through regardless of how I change the code around.
The problem occurs in this function, and only this function, even though I have a couple of similar functions that work perfectly fine.
Code:
function findClosestTeamPlanet(VECTOR* pos,team) {
	var count = 0;
	var dist1 = 0;
	var dist2 = 65535;
	ENTITY* temp_ent = NULL;
	ENTITY* temp_ent2 = NULL;
	
	for (count = 0; count < 255; count ++) {
		if (planets[count] != 0) {
			temp_ent = ptr_for_handle(planets[count]);
			if (temp_ent != NULL) {
				dist1 = vec_dist(temp_ent.x,pos);
				if (dist2 > dist1 && temp_ent.skill18 == team) {
					dist2 = dist1;
					temp_ent2 = temp_ent;
				}
			}
		}
	}
	return temp_ent2;
}



The error is thrown at the line 'dist1 = vec_dist(temp_ent.x,pos);', which I would expect to be prevented by the line just before that - but it isn't. Anyone have any idea why that might be?
Thanks in advance!
~TehV

EDIT: Changed the title. Problem was solved.

Last edited by TehV; 10/11/12 20:00.
Re: Empty pointer? [Re: TehV] #409109
10/11/12 19:16
10/11/12 19:16
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Have you checked that the vector pointer 'pos' is non-NULL before calling this function?


Always learn from history, to be sure you make the same mistakes again...
Re: Empty pointer? [Re: Uhrwerk] #409110
10/11/12 19:27
10/11/12 19:27
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
It shouldn't be NULL, I'm passing an existing entity's position to the function.
I'll double-check it though to make sure.

Re: Empty pointer? [Re: TehV] #409111
10/11/12 19:45
10/11/12 19:45
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Try
dist1 = vec_dist(temp_ent.x,nullvector);
and
dist1 = vec_dist(nullvector,pos);
If the first approach crashes, set planets[x] manually to zero when you remove planet x.
If that doesn't help too, try to isolate the problem with sys_marker.


"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: Empty pointer? [Re: Superku] #409115
10/11/12 19:58
10/11/12 19:58
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
I tried both of the approaches. The first one worked, the second one didn't. I checked the parameters I passed to the function after Uhrwerk's post.

Conclusion: I messed up big time. I mixed up the parameters, passing a number and a vector instead of a vector and a number like the function expects me to. It's obvious why that won't work, and of course I didn't think of checking that. Instead, I spent a while fiddling around with a function that works perfectly fine and then posted about an error that doesn't exist.
I switched the parameters around and it works now. I thank you both for your efforts to help me out, and I apologize for wasting your time. frown

Re: Empty pointer? [Re: TehV] #409117
10/11/12 20:07
10/11/12 20:07
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
No problem, such mistakes happen to all of us.


"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: Empty pointer? [Re: TehV] #409129
10/11/12 22:52
10/11/12 22:52
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: TehV
I thank you both for your efforts to help me out, and I apologize for wasting your time.

This has got absolutely nothing to do with wasting someones time. Sometimes you're blind when looking at your own code and just need a small push in the right direction. Today it was you, tomorrow it will be me. Besides: your problem description was very precise and clear and that is already half the way to go.


Always learn from history, to be sure you make the same mistakes again...

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1