Hi,
This post follow the last one I've made concerning pointers.
Just to tell that I encounter a strange behaviour. Something that appear not logic for me.
To define an object, I created a structure called : Object3DType:
struct Object3DStruct{
int ...;
float ...;
...
};
typedef struct Object3DStruct Object3DType;
I've also defined a type for a pointer to this kind of structures :
typedef Object3DType *Object3DPointer;
Up to here, everything should be ok.
I create a blank memory for storing a list of 256 objects pointers :
Object3DPointer *ObjectList;
ObjectList = IExec->AllocMem( 512 * (int*), MEMF_CLEAR );
ObjectList is then the pointer to the freshly created memory location to store 512 objects pointers.
( pointer to an array of 512 Object3DPointer )
Now, when I create a new 3D Object, I do this :
Object3DPointer NewObject;
NewObject = IExec -> AllocMem( sizeof( Object3DType ), MEMF_CLEAR );
and to store this pointer in the list, I do this :
AddObjectToList( ObjectID, NewObject);
Here is the AddObjectToList function:
void AddObjectToList( int ObjectID, Object3DPointer ObjectPTR ){
if ( ObjectID >> 0 ){
if (Basic3D.ObjectListAmount < ObjectID ){
ResizeObjectList( ObjectID );
}
ObjectList[ ObjectID ] = ObjectPTR;
Basic.ObjectAmount++;
}
}
The first thing that is wrong for me is that I should logically do this :
*ObjectList[ ObjectID ] = ObjectPTR;
To write in the memory location at offset ( ObjectID * 4 ) but if I do this, I get an error telling that types are incompatibles ...
The second thing is now when I want to get the pointer of the object. I do this :
Object3DPointer MyObject;
MyObject = GetObjectPTR( ObjectID );
I should then, following the AddObjectToList quotes, do this :
Object3DPointer GetObjectPTR( int ObjectID )[
Object3DPointer NewObjectPTR = NULL;
if ( ObjectID > 0 ){
if ( ObjectID <= Basic3D.ObjectListAmount ){
NewObjectPTR = ObjectList[ ObjectID ];
}
}
return NewObjectPTR;
}
If I do all of these, my program crash... strange.
if I simply change 1 line with :
NewObjectPTR = &ObjectList[ ObjectID ];
The program run fine ...
Why ???
Can someone light me about these odd things ?
I'm sure I'm doing something wrong with pointer of pointer array but I don't find any solution.
Thank you
Regards,
Freddix/AmiDARK.