Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TedMar, AndrewAMD), 1,043 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
how to call ptr_for_handle without "crash" #365885
03/29/11 21:52
03/29/11 21:52
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
When I create a handle of an object,
remove the object (ent_remove)
and retreive it (ENITY) later with
ptr_for_handle,
the engine will call an error on warn_level > 1

But checking if the handle is NULL before retreiving the pointer does not work.

How do I know if a handle is empty, or an invalid (removed) object
BEFORE calling ptr_for_handle?

Example:

Code:
for(i=0;i<counter;i++)
{
	if(entities[i]!=0)  //DOES NOT RESPOND TO NULL
	{
		//will cause an error thrown
		testEnt=ptr_for_handle(entities[i]);
		
		//well here I can check if its NULL, but thats too late

		if( checkEnt!=NULL)
		{
			...

		}
	}
}


....

ent_remove(entityToKill); //killing an entity at some time



Re: how to call ptr_for_handle without "crash" [Re: Oxy] #365888
03/29/11 22:31
03/29/11 22:31
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
any idea how to check a handle, if its valid?

Re: how to call ptr_for_handle without "crash" [Re: Oxy] #365889
03/29/11 22:40
03/29/11 22:40
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
As far as i remember you are doing it the right way. entites[i] is a var array and the entites are saved with handle(ENTITY*) there, right?

when warn_level is set > 1, a warning is issued, but you can ignore it. only solution is to set warn_level to 1.

Re: how to call ptr_for_handle without "crash" [Re: SchokoKeks] #365890
03/29/11 22:45
03/29/11 22:45
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
But why is there no way to check if a handle is null,
before having the engine issue a warning.

There must a a "right" way to handle this.
Or did the engine creators forget about this
(rather standard) case?
some command like ptr_is_valid(handleid);


by lowering the warn_level I would miss other errors,
that could come up.

Re: how to call ptr_for_handle without "crash" [Re: Oxy] #365891
03/29/11 22:50
03/29/11 22:50
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
entities[entityToKill.id] = 0;
ent_remove(entityToKill);

Is that an acceptable workaround for you?


"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: how to call ptr_for_handle without "crash" [Re: Superku] #365892
03/29/11 22:59
03/29/11 22:59
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
No, after the entity is removed, its pointer is null/invalid (and thus all skills are unreadalbe),
and I operate on a list of handles to entities, read out
by other codeparts.

I guess its simply an engine flaw, to miss
a robust way to check for valid handles, without a
warning thrown.

When I develop something, I always like to have errors thrown and not swallowed,
but not if there is no correct way to handle it.



But thanks for your help

Re: how to call ptr_for_handle without "crash" [Re: Oxy] #365897
03/30/11 00:01
03/30/11 00:01
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Quote:
No, after the entity is removed, its pointer is null/invalid (and thus all skills are unreadalbe),
and I operate on a list of handles to entities, read out
by other codeparts.

I don't understand. When you remove the entity, simply set the corresponding handle to zero, i.e. before the ptr_/ent_remove instruction.
Then, in your list of handles, the handle will be zero and thus can be ignored, so you don't have to call ptr_for_handle anymore.


"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: how to call ptr_for_handle without "crash" [Re: Superku] #365898
03/30/11 00:10
03/30/11 00:10
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
I know what you mean.
But there is not only a single array for each handle.

There are many possible locations, and references where it
could have been stored before.
And I cant resolve all of them.
So this would be only a workaround for this specific case.

Re: how to call ptr_for_handle without "crash" [Re: Oxy] #365901
03/30/11 00:40
03/30/11 00:40
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Ok, then you could/ should contact the developers so ptr_for_handle returns NULL when the handle is invalid.


"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: how to call ptr_for_handle without "crash" [Re: Superku] #365904
03/30/11 02:07
03/30/11 02:07
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
Right now I have the problem that a removed entity
is not recognized as NULL, but
is like a "ZERO" entity, with positiondata at 0,0,0 for example.

This engine really has some flaws.


if(myTarget!=NULL)
{
if((myTarget.x==0) && (myTarget.z==0) ) {ent_remove(myTarget);}

-> results in a crash, because myTarget is NULL ...

so first its Not Null, then its Null...
Very good engine programming

Page 1 of 2 1 2

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