Rider
09-19-2008, 07:18 AM
Whenever my program reaches the point where the array 'starcoor' is being used in any way, the program just crashes. No error messages, the window disappears and that's it. I'm not sure what's wrong...
Oh, I have SDL linked, which is what is drawing the window... in case that's relevant :)
//Relevant defines
const int X_OFFSET = 9;
const int Y_OFFSET = 12;
// Galaxy attributes
const int GALAXY_WIDTH = 2000;
const int GALAXY_HEIGHT = 2000;
//RoundN procedure
int roundn(double a) {
return int(a + 0.5);
}
void generategalaxy( int gal )
{
fprintf(stderr, "Reached: Generate Galaxy\n");
int GW = roundn(GALAXY_WIDTH / X_OFFSET) + 1;
int GH = roundn(GALAXY_HEIGHT / Y_OFFSET) + 1;
int starcoor[GW][GH];
int tmpa = 0;
int tmpstar = 0;
int fact = 0;
int fact2 = 0;
int tmpx = 0;
int tmpy = 0;
int tmpsiz = 0;
int tmpcol = 0;
while ( tmpstar < 1300 )
{
fprintf(stderr, "Reached: Star creator loop\n");
tmpa = 0;
if ( fact > 150 ) { fact = 0; fact2 += 25; }
if ( fact2 > 130 ) { fact2 = 40; }
tmpx = roundn(-110 + (randnum(0,20*3)) + fact);
tmpy = roundn(-80 + (randnum(0,10*3)) + fact2 );
tmpsiz = randnum(0,7);
tmpcol = randnum(0,7);
if ( tmpx == 0 ) { tmpx = 1; }
bool donecheck = false;
fprintf(stderr, "Reached: Starcoor check\n");
if ( starcoor[tmpx][tmpy] == 0 )
{
fprintf(stderr, "Star made: ( ");
inttoerr(tmpx); fprintf(stderr, ", ");
inttoerr(tmpy); fprintf(stderr, ", ");
inttoerr(tmpcol); fprintf(stderr, ", ");
inttoerr(tmpsiz); fprintf(stderr, " )\n");
star[gal][tmpstar][0] = tmpx;
star[gal][tmpstar][1] = tmpy;
star[gal][tmpstar][2] = tmpcol;
star[gal][tmpstar][3] = 0;
star[gal][tmpstar][4] = tmpsiz;
starcoor[tmpx][tmpy] = 4;
tmpstar++;
fact++;
}
}
}
Oh, I have SDL linked, which is what is drawing the window... in case that's relevant :)
//Relevant defines
const int X_OFFSET = 9;
const int Y_OFFSET = 12;
// Galaxy attributes
const int GALAXY_WIDTH = 2000;
const int GALAXY_HEIGHT = 2000;
//RoundN procedure
int roundn(double a) {
return int(a + 0.5);
}
void generategalaxy( int gal )
{
fprintf(stderr, "Reached: Generate Galaxy\n");
int GW = roundn(GALAXY_WIDTH / X_OFFSET) + 1;
int GH = roundn(GALAXY_HEIGHT / Y_OFFSET) + 1;
int starcoor[GW][GH];
int tmpa = 0;
int tmpstar = 0;
int fact = 0;
int fact2 = 0;
int tmpx = 0;
int tmpy = 0;
int tmpsiz = 0;
int tmpcol = 0;
while ( tmpstar < 1300 )
{
fprintf(stderr, "Reached: Star creator loop\n");
tmpa = 0;
if ( fact > 150 ) { fact = 0; fact2 += 25; }
if ( fact2 > 130 ) { fact2 = 40; }
tmpx = roundn(-110 + (randnum(0,20*3)) + fact);
tmpy = roundn(-80 + (randnum(0,10*3)) + fact2 );
tmpsiz = randnum(0,7);
tmpcol = randnum(0,7);
if ( tmpx == 0 ) { tmpx = 1; }
bool donecheck = false;
fprintf(stderr, "Reached: Starcoor check\n");
if ( starcoor[tmpx][tmpy] == 0 )
{
fprintf(stderr, "Star made: ( ");
inttoerr(tmpx); fprintf(stderr, ", ");
inttoerr(tmpy); fprintf(stderr, ", ");
inttoerr(tmpcol); fprintf(stderr, ", ");
inttoerr(tmpsiz); fprintf(stderr, " )\n");
star[gal][tmpstar][0] = tmpx;
star[gal][tmpstar][1] = tmpy;
star[gal][tmpstar][2] = tmpcol;
star[gal][tmpstar][3] = 0;
star[gal][tmpstar][4] = tmpsiz;
starcoor[tmpx][tmpy] = 4;
tmpstar++;
fact++;
}
}
}