Posted by Flikm on 04:52:00 04-24-2002
im having some strange problems with the map blitting part of my RPG. ive been working on this for a week and a half with no success. ive asked a lot of people, but nobody seemed to know. heres 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, screws up here the second time around
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)
}
[ This Message was edited by: Flikm on 2002-04-24 04:59 ]
Posted by -KEN- on 10:17:00 04-24-2002
What exactly are the problems that you're having?
[addsig]
Posted by KaGez on 13:18:00 04-24-2002
you use double buffering?
then I think you should flip the buffers instead of updating it...
just a thought
[addsig]
Posted by MoX on 15:01:00 04-24-2002
Yeah, and that should stop that ugly flickering...
[addsig]
Posted by KaGez on 17:16:00 04-24-2002
hehe, ture... you must've had some great flickering
but I wonder why nobody could help you with that :/
[addsig]
Posted by Flikm on 04:17:00 04-25-2002
ok, but it never gets to that line anyways. it segfaults when i call DisplyImage the second time.
Posted by KaGez on 16:20:00 04-26-2002
I'd highly advise you to let it go through GDB (or DDD) or some other debigger and check for buffer overflows and such.
[addsig]
Posted by MoX on 16:54:00 04-26-2002
Flikm: I need to know your code more exactly to say more, but it sounds like you are using some pointer which points to a local variable...(which segfaults later cause it has been freed automatically) - just a guess.
[addsig]
Posted by KaGez on 21:34:00 04-26-2002
yeah, we can guess much, that's why I say that he should use a debugger
[addsig]
Posted by Flikm on 04:16:00 04-27-2002
hey, thx all. i got it fixed with some help from #sdl on openprojects. it was ONE line the whole time (2 weeks). im not supposed to free the image ...
Posted by KaGez on 11:02:00 04-27-2002
lol
I think the debugger could've helped you with that
[addsig]
Posted by MoX on 19:37:00 04-27-2002
Gaahhh! Never (in life) free something you still have a pointer to!!!!!!
[addsig]
Posted by KaGez on 22:11:00 04-28-2002
lol... I've also made a little discovery with GLut and X
I didn't know that just leaving out one littl "&" could crash your whole X
_always_ use glutDisplayFunc(&funcname);
[addsig]