|
I need some outsider's perspective...
#416849
02/05/13 13:40
02/05/13 13:40
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
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...
#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...
#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.
|
|
|
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
Senior Expert
|
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:
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
OP
User
|
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...
#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...
|
|
|
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
Expert
|
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.
|
|
|
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
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
until you spent your time with laughing I made for you a working example:
#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.
|
|
|
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
OP
User
|
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.
|
|
|
|