Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Spirit, tomaslolo, Akow, NnamueN, 1 invisible), 1,495 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
I need some outsider's perspective... #416849
02/05/13 13:40
02/05/13 13:40
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Sometimes you have been looking at your own code for so long you just can't see past it, and the simplest mistakes become invisible to you no matter how much experience you have... Has this ever happened to you? Well I'm completely stuck. I have even tried reducing the function to basically do NOTHING and I still can't find my error...

I have the feeling the problem is so simple and obvious it is probably even embarrasing, but I am just blind to to my own code?



The function used to be usefull, but I reduced it to a bare minimum. Now it does nothing and I still cant figure ouut what is wrong...
Code:
#include <acknex.h>
#include <default.c>

int testi;

void world_waterORland()
{
   testi++;//1
   
	int Bwater[1000][500];
	int tx,ty;
	
	testi++;//2
	
	int temp_alpha;
	
	testi++;//3
	
	for(tx=0;tx<1000;tx++)
	{
		for(ty=0;ty<500;ty++)
		{
		   testi=4;//4
		   wait(1);
			if(temp_alpha<10)
			{
				Bwater[tx][ty]=1;//yes=water
			}
			else
			{
				Bwater[tx][ty]=0;//no=land
			}
		}
	}
	
	testi=5;//5
}

void main()
{
	fps_max=60;
	level_load(NULL);
	wait(1);
	
	
	world_waterORland();
	
	while(1)
	{
		wait(1);
	}
}



"testi" is just an integer I put in there to find out where it stops.
-(this code usually produces an E1513) testi reaches 3, but not 4... So that would indicate the declaration of the "for" loops are causing the problem? Because it reaches them but never enters?
-(when I remove the "wait(1);" right after "testi=4;" my code sometimes just crashes with no error message) When this happens testi reaches 4 but not 5, which would indicate a crash inside the loops...


The original code was trying to retrieve information from an image file (map), that has a heightmap "hidden" in it's alpha values, to later create a randomized level based on it...
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>

BMAP* earth_water = "earthnuclearC.tga";
int testi;

void world_waterORland()
{
   testi++;
	int Bwater[1000][500];
	int tx,ty;
	
	testi++;
	var format; var pixel;
	var t_alpha;
	COLOR* t_color;
	format = bmap_lock(earth_water,0);
	testi++;
	
	for(tx=0;tx<1000;tx++)
	{
		for(ty=0;ty<500;ty++)
		{
		   testi++;
		   wait(1);
			pixel = pixel_for_bmap(earth_water,x,y);
			t_color=pixel_to_vec(NULL,t_alpha,format,pixel);
			if(t_alpha<10)
			{
				Bwater[tx][ty]=1;//yes=water
			}
			else
			{
				Bwater[tx][ty]=0;//no=land
			}
		}
	}
	bmap_unlock(earth_water);
	testi++;
}

void main()
{
	fps_max=60;
	level_load(NULL);
	wait(3);
	
	
	world_waterORland();
	
	while(1)
	{
		wait(1);
	}
}



I must add, even though the problem is probably so simple it is even embarrasing... I do have alot of experience in programming in general and Lite-C. As many of you know, I have been messing around with 3DGS for a few years already, but I just cannot seem to look past my own code, my brain is just blocked on this one.


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: I need some outsider's perspective... [Re: Carlos3DGS] #416856
02/05/13 14:19
02/05/13 14:19
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
The amount of memory you can allocate on the fly like this
int Bwater[1000][500];
is limited, especially with recursive functions you have to take special care. Let's say you have a function like this:
Code:
void manipulate_array(int i)
{
var local_array[1024];
... do something with the array
if(i < 256) manipulate_array(i+1);
}
...
manipulate_array(0);


This will work a few times and it does not look like a lot of memory but at some level the statement "var local_array[1024];" will not allocate an array successfully and your game will crash after some array manipulation or do weird and seemingly unreasonable things.
The solution is too use sys_malloc and sys_free manually.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: I need some outsider's perspective... [Re: Superku] #416859
02/05/13 14:41
02/05/13 14:41
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
The thing is, that it is not a recursive function. And unless I am missing something this function only gets called once in my code posted above. If my calculations are correct the above code should only be allocating less than 2MB of memory once, yet I am still getting this error.

And originally my code used "BOOL Bwater[1000][500];" which would only allocate 61KB? once? Yet I got the same error...

You can see my main function posted in the code above if you want to check that also, because whatever the problem is, I just cannot see it... I feel so stupid right now...

Mabe it is just a problem with my 3DGS installation being corrupted? Or a hardware failure (memory/hard drive)? Could someone else run this code and check if it crashes for them? To my eyes it really should work...

Code:
#include <acknex.h>
#include <default.c>

int testi;

void world_waterORland()
{
   testi++;//1
   
	int Bwater[1000][500];
	int tx,ty;
	
	testi++;//2
	
	int temp_alpha;
	
	testi++;//3
	
	for(tx=0;tx<1000;tx++)
	{
		for(ty=0;ty<500;ty++)
		{
		   testi=4;//4
		   //wait(1);
		   
			if(temp_alpha<10)
			{
				Bwater[tx][ty]=1;//yes=water
			}
			else
			{
				Bwater[tx][ty]=0;//no=land
			}
				testi=5;//5
		}
	}
	testi=6;//6

}

void main()
{
	fps_max=60;
	level_load(NULL);
	wait(1);
	
	
	world_waterORland();
	
	while(1)
	{
		wait(1);
	}
}



Basically, if someone gets a small blue window, with no error messages or crashes... I might have a hardware failure that at the moment I dont think I can afford to fix...
If anyone gets a small blue window, just press ESC, and post me the bad news...


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: I need some outsider's perspective... [Re: Superku] #416860
02/05/13 14:44
02/05/13 14:44
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
I also had strange error messages resulting from large arrays, so better to use sys_malloc and sys_free, it should work...

bool is 4 bytes in lite-c

Last edited by sivan; 02/05/13 14:45.

Free world editor for 3D Gamestudio: MapBuilder Editor
Re: I need some outsider's perspective... [Re: sivan] #416862
02/05/13 14:50
02/05/13 14:50
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
BOOL is 4B in Lite-C? Well... that sucks! What is the point of using a BOOL instead of INT or VAR then? hahahaha
*Note to brain: never use BOOL again... Use CHAR instead...

Are SHORT and CHAR also using 4B instead of 2B & 1B?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: I need some outsider's perspective... [Re: sivan] #416864
02/05/13 14:53
02/05/13 14:53
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
As I've said, the reason for the crash is the size of the array. Allocate the memory manually.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: I need some outsider's perspective... [Re: Superku] #416865
02/05/13 14:56
02/05/13 14:56
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
until you spent your time with laughing I made for you a working example:

Code:
#include <acknex.h>
#include <default.c>

int testi = 0;
int** Bwater = NULL;

void world_waterORland()
{
   testi++;//1
   
   Bwater = (int**)sys_malloc( (int)1000 * sizeof(int*) );			// ###
   int j;
	for (j=0;j<1000;j++)
		{
			Bwater[j] = (int*)sys_malloc( (int)500 * sizeof(int) );
			memset( Bwater[j] , (int)100 , (int)500 * sizeof(int) ); 	
		}
//	int Bwater[1000][500];

	int tx,ty;
	
	testi++;//2
	
	int temp_alpha;
	
	testi++;//3
	
	for(tx=0;tx<1000;tx++)
	{
		for(ty=0;ty<500;ty++)
		{
		   testi=4;//4
		   //wait(1);
		   
			if(temp_alpha<10)
			{
				(Bwater[tx])[ty]=1;//yes=water
			}
			else
			{
				(Bwater[tx])[ty]=0;//no=land
			}
				testi=5;//5
		}
	}
	testi=6;//6

}

void main()
{
	fps_max=60;
	level_load(NULL);
	wait(1);
	
	
	world_waterORland();
	
	while(1)
	{
		wait(1);
	}
}


Last edited by sivan; 02/05/13 14:59.

Free world editor for 3D Gamestudio: MapBuilder Editor
Re: I need some outsider's perspective... [Re: Superku] #416866
02/05/13 15:00
02/05/13 15:00
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Thankyou both Sivan and Superku

@Superku:
when you first stated the size of the array was the problem I though you meant using too much, as in, more than 2GB due to a memory leack in my code, or recursive functions since you mentioned them. I didnt understand the engine had problems allocating "relatively" small amounts of memory even if I had it available. Sorry for the confusion.

@Sivan:
Thankyou very much for that code, up until now I had only used malloc for structs (linked lists). Your example will save me time and headaches getting around to learning to use it with arrays. Thanks!

EDIT:
I am still curious though. Do short and char properly use 2B and 1B respectively? Or do they use 4B like bool?

Last edited by Carlos3DGS; 02/05/13 15:08.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: I need some outsider's perspective... [Re: Carlos3DGS] #416883
02/05/13 16:22
02/05/13 16:22
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
The manual has a page about variables and arrays, there is a list with the sizes of each primitive datatype. Alternatively you can use the sizeof macro and for example printf to determine the size(s) experimentally.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: I need some outsider's perspective... [Re: Superku] #416896
02/05/13 19:00
02/05/13 19:00
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Now that I am home I have been looking at the code more carefully but I have a couple of questions.

1. Would a simple "free(Bwater);" be enough to free the memory used by the whole 1000X500 array? Or would I have to use multiple free() instructions inside a loop like when you malloc()?

2. I dont understand what you are doing in this instruction:
"memset( Bwater[j] , (int)100 , (int)500 * sizeof(int) );"
Are you setting the whole column to 100 as if it were one huge number? I am lost with this part


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Page 1 of 5 1 2 3 4 5

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

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