Well the first problem is described pretty fast.
I declare a global pointer
the whole thing runs fine. Though when in debugging mode the engine crashes as soon as I in- or decrease the pointer by one. As well if I initialize it with something != 0 the engine crashes instantly when started in debugging mode.
I use Atari Lite-C free edition.
And here comes the second problem.
I got following struct
typedef struct ENT2D
{
OBJECT* objData; //this one simply contains information on filenames for the panels in this struct and the number of panels it should have.
PANEL** objParts;
STRING* EntityName;
int posX;
int posY;
}ENT2D;
and a global variable "ENT2D* ObjectPreview".
As you can see it contains an array of panels. The thing is I want to change the panels of the variable in runtime. This works pretty good but the thing is that the old panels won't get deleted. The following is the function which I use to morph the Object from one to the other.
//Notice! Although this is called Entity it's not an 3D-Entity but simply a collection of panels colledted in a struct.
//The ptrToNewObject contains the position offset of the pointer in the GSVector (see [url=http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=255591#Post255591]GSVector plugin[/url]) to the data used to which the ENT2D is supposed to be morphed to.
function morphEntity(ENT2D* EntityToMorph, byte* ptrToNewObject)
{
//here I get the pointer to the needed Object-Data like number of panels needed for the object, filenames for the panel bitmaps and position of the panels relative to the ENT2D origin.
OBJECT* newObjectData = (int*)getFromGSVector(Objekte, ptrToNewObject);
if(!EntityToMorph) //Is the pointer to the struct = NULL?
EntityToMorph = (ENT2D*)malloc((int)sizeof(ENT2D)); //Alright! allocate some memory!
else //otherwise
{
int index;
if(!(EntityToMorph.objParts == NULL)) //is there already a pointer to an array of panels?
{
for(index = 0; index < EntityToMorph.objData.parts; index++) //go through every array element
{
if((EntityToMorph.objParts)[index]) //check if there is a pointer to a panel
ptr_remove((EntityToMorph.objParts)[index]); //and delete it
}
free(EntityToMorph.objParts); then free the pointer to the array of panels
}
free(EntityToMorph); //free the struct pointer
EntityToMorph = (ENT2D*)malloc((int)sizeof(ENT2D)); // now we need new memory for the new 2D-Entity
}
// the rest is not of interes as far as I understand the problem as the actual panel clearing should happen in the above part of the code.
EntityToMorph.objParts = (PANEL**)malloc((int)(sizeof(PANEL*)*newObjectData.parts));
EntityToMorph.objData = newObjectData;
EntityToMorph.EntityName = newObjectData.objName;
int index;
for(index = 0; index < newObjectData.parts; index++)
{
STRING* panCreateString = "";
str_cat(panCreateString, "pos_x = ");
str_cat(panCreateString, str_for_num(NULL, 500+(newObjectData.panInfo)[index].posX));
str_cat(panCreateString, "; pos_y = ");
str_cat(panCreateString, str_for_num(NULL, 60+(newObjectData.panInfo)[index].posY));
str_cat(panCreateString, "; bmap = \"");
str_cat(panCreateString, (newObjectData.panInfo)[index].bmpName);
str_cat(panCreateString, "\"; flags = SHOW; on_click = createNewEntity; ");
if((newObjectData.panInfo)[index].passable)
int panLayer = 15;
else
int panLayer = 16;
(EntityToMorph.objParts)[index] = pan_create(panCreateString, 550);
(EntityToMorph.objParts)[index].size_x = (EntityToMorph.objParts)[index].bmap.width;
(EntityToMorph.objParts)[index].size_y = (EntityToMorph.objParts)[index].bmap.height;
}
free(newObjectData);
}
maybe someone could point me out what I'm doing wrong here?
greetings
KDuke