here is the code:
Code:
/* this is a member of "map" which has:
string name;
int ref_num;
int w, h;
tileset tiles;
int tileset_ref;
vector< vector<int> > data;
tileset has:
string name;
int ref_num;
vector<SDL_Surface*> tile;
SDL_Surface is the thing that SDL uses or the screen and images
*/
void view( int x, int y ){
if( x > w || y > h ) return; //if x is larger than the width of the map or y the height, something is wrong
int i, j, tempx;
fillrect( screen, 0, 0, screen->w, screen->h, black ); //clear the screen
tempx = x;
//notice that data has data stored like this: data[up and down][side to side]
for( i = 0; i != screen->h/32; i++ ){
for( j = 0; j != screen->w/32; j++ ){
DisplayImage( screen, tiles.tile[ data[y][x] ], j * TILE_W, i * TILE_H );
//DisplayImage( SDL_Surface *dest, SDL_Surface *image, x, y ) x, y of the top left corner
if( x == w ) break;
x++;
}
if( y == h ) break;
x = tempx;
y++;
}
SDL_UpdateRect( screen, 0, 0, 0, 0 ); //update the whole screen (double buffering)
}
the line "DisplayImage( screen, tiles.tile[ data[y][x] ], j * TILE_W, i * TILE_H );" is segfaulting when the loop within the larger is on its second round. data[y][x] is he same value both the first and second times.