|
Re: how to call ptr_for_handle without "crash"
[Re: Oxy]
#365926
03/30/11 12:51
03/30/11 12:51
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
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 Removed entities are not NULL. An Entity cannot be NULL. NULL is a value that can be assigned to pointers. Lite-C has no way of finding out where you saved pointers to entities and set them automatically to NULL for you. Your code crashes because myTarget is a vagabonding pointer, not because it is NULL and suddenly not NULL. A value different from NULL does not mean a pointer is necessarily valid. http://tutorial.3dgamestudio.net/
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: how to call ptr_for_handle without "crash"
[Re: Damocles_]
#365932
03/30/11 13:37
03/30/11 13:37
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
You can easily do that yourself by iterating over the engine objects with ptr_first (void* object). If the pointer you want to check is amongst the engine objects it is valid, otherwise it is not. However, this is not recommendable in terms of speed and won't work for other memory blocks you have allocated yourself.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
|