SDL error
hey i got an error that dosnt show when i compile all i get is: SEGMENTION FAULT (SDL PARACHUTE DEPLOYED) the code is:
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
SDL_Surface *screen;
void ShowBMP(char *file, SDL_Surface *screen, int x, int y);
int i;
int x;
int y;
int bytecount;
int main()
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Una
ble to init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}
makemap();
}
int makemap()
{
fprintf(stderr, "MakeMapfunction\n");
SDL_Surface *screen;
FILE
*count;
long size;
count = fopen ("desert.map","rb");
if (count==NULL) perror ("Error opening file");
else
{
fseek (count, 0, SEEK_END);
size=ftell (count);
fclose (count);
printf ("Size of myfile.txt: %ld bytes.\n",size);
bytecount = size;
printf("\n\n%i\n\n", bytecount);
}
fprintf(stderr, "52\n");
FILE *file;
file=fopen("desert.map","r");
if ( !fil
e )
{
printf ( "Unable to open file!" );
exit ;
}
fprintf(stderr, "61\n");
if(i<=bytecount)
{
i = 0;
bytecount = 0;
}
while(i<=bytecount)
{
beginning:
fseek(file,i,SEEK_SET);
int c = fgetc(file);
fprintf(stderr, "67\n");
if(c=='W')
{
ShowBMP("gfx/water.bmp", screen, x, y);
fprintf(stderr, "73\n");
}
else if(c=='D')
{
ShowBMP("gfx/desert.bmp", screen, x, y);
f
20:56:50
printf(stderr, "79\n");
}
else if(c=='G')
{
ShowBMP("gfx/grass.bmp", screen, x, y);
fprintf(stderr, "85\n");
}
else if(c=='\n')
{
y = y + 32;
}
i = i + 1;
x = x + 32;
fprintf(stderr, "94\n");
}
fclose(file);
}
void ShowBMP(char *file, SDL_Surface *screen, int x, int y)
{
SDL_Surface *image;
SDL_Rect dest;
/* Load the BMP file into a surface */
image =
20:56:51
SDL_LoadBMP(file);
if ( image == NULL ) {
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
return;
}
/* Blit onto the screen surface.
The surfaces should not be locked at this point.
*/
dest.x = x;
dest.y = y;
dest.w = image->w;
dest.h = image->h;
SDL_BlitSurface(image, NULL, screen, &dest);
/* Update the changed portion of the screen */
SDL_UpdateRects(screen, 1, &dest);
}
You have an extra definition of screen in your showmap function.
edit: AND your parameter to showBMP is also called screen.
you should try to avoid overlapping names.
edit: AND your parameter to showBMP is also called screen.
you should try to avoid overlapping names.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement