Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,654 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
I've got leaks... btw. FREAKIN pointers! #256635
03/17/09 21:05
03/17/09 21:05
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline OP
Member
KDuke  Offline OP
Member
K

Joined: Mar 2009
Posts: 112
Germany
Well the first problem is described pretty fast.
I declare a global pointer
Code:
byte* ObjectPointer = 0

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
Code:
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.

Code:
//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


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: I've got leaks... btw. FREAKIN pointers! [Re: KDuke] #256764
03/18/09 21:52
03/18/09 21:52
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline OP
Member
KDuke  Offline OP
Member
K

Joined: Mar 2009
Posts: 112
Germany
Well I finally solved the Problem!
I simply forgot to use the "->" operator to acces the structs instead of the "." operator.

greetings
KDuke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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