Gamestudio Links
Zorro Links
Newest Posts
What are you working on?
by rayp. 10/15/25 20:44
Help!
by VoroneTZ. 10/14/25 05:04
Zorro 2.70
by jcl. 10/13/25 09:01
ZorroGPT
by TipmyPip. 10/12/25 13:58
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 10/11/25 18:45
Reality Check results on my strategy
by dBc. 10/11/25 06:15
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (AndrewAMD), 7,782 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
joenxxx, Jota, krishna, DrissB, James168
19170 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Errr. DUH! Need help with advanced SYS_MALLOCing please. [Re: Uhrwerk] #388576
12/04/11 16:59
12/04/11 16:59
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
But unfortunately your snippet doesnt work well with size of ARRAYS of objects.

But regardless of that... ITS WORKING!!! And the way I wanted it to also!
In the spoiler below is a cut & paste straight from my project.

It turns out that it was a simple sloppiness in my bracket usage that was screwing
me up and causing an array overflow, into some other space.

If you look in the spoiler, in the "create_entities" function you will NOW find
Code:
sys_malloc(sizeof(ENTITY*)*(LOD_count[LOD]+1))

My problem was was that I left out an important pair of brackets near the end...
Code:
sys_malloc(sizeof(ENTITY*)*LOD_count[LOD]+1)

Look carefully! And you will see when I filled the last element of the array
it would overflow the end of the malloc'ed area by three bytes!

Im not sure WHAT it was overflowing INTO, but it was obviously critical!

So before I say "nyha nyha, I was right and you were wrong!!", I will say that
this is still only a VERY small testbed project for proof-of-concept testing.
So there is not much 'happening' in it yet. So as more functionality of the
concept under test goes in, it may yet prove you right over me.
(in regards to how the engine handles declares like "ENTITY** slab[4];" that is)

Click to reveal..
Code:
ENTITY** slab_ents[4];		//slab_ent store of EACH LOD entities		(index = LOD number)


void create_entities()
{
	...
	// Create Entities in Appropriate slab_ents STORE
	cnt=0;	for(LOD=0; LOD<4; LOD++)
	{	
		(slab_ents[LOD]) = (ENTITY**)sys_malloc(sizeof(ENTITY*)*(LOD_count[LOD]+1));
		for(i=0; i<LOD_count[LOD]; i++)
		{	
			(slab_ents[LOD])[i] = ent_create(LOD_names[LOD], S_PARK, NULL);
			set((slab_ents[LOD])[i], INVISIBLE);	ent_clone((slab_ents[LOD])[i]);
		}	
		(slab_ents[LOD])[i] = NULL;
	}			
}


void slabs_terminate()
{	
	var LOD, i;		
	for(LOD=0; LOD<4; LOD++)	
	{	
		i=-1;	
		while((slab_ents[LOD])[i++])
		{	ent_remove((slab_ents[LOD])[i]);		}
		sys_free(slab_ents[LOD]);
	}
}


Thanks for the help dude. You made me think in "unusual" ways and so I was
able to find the problem while I was in there...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Errr. DUH! Need help with advanced SYS_MALLOCing please. [Re: Uhrwerk] #388635
12/05/11 11:02
12/05/11 11:02
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
hi
some months ago I also had problems with my dynamic struct array (but I had to use malloc and realloc to keep it expandable), and finally I made a conclusion to create a small test program printing out values... the best always to visualize what happens behind laugh (especially because I'm always making banal errors)


Free world editor for 3D Gamestudio: MapBuilder Editor
Page 2 of 2 1 2

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