3 registered members (AndrewAMD, VoroneTZ, 1 invisible),
1,578
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Empty pointer? (Solved)
#409107
10/11/12 18:59
10/11/12 18:59
|
Joined: Mar 2010
Posts: 120 Switzerland
TehV
OP
Member
|
OP
Member
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.
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
Expert
|
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: Superku]
#409115
10/11/12 19:58
10/11/12 19:58
|
Joined: Mar 2010
Posts: 120 Switzerland
TehV
OP
Member
|
OP
Member
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.
|
|
|
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
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
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...
|
|
|
|