IMG_pnm.c
changeset 118 c5e736a47ad2
parent 117 e613cf987897
child 119 336c49447e0d
     1.1 --- a/IMG_pnm.c	Sat Feb 04 20:37:17 2006 +0000
     1.2 +++ b/IMG_pnm.c	Sat Feb 04 22:26:04 2006 +0000
     1.3 @@ -105,6 +105,7 @@
     1.4  
     1.5  SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)
     1.6  {
     1.7 +	int start;
     1.8  	SDL_Surface *surface = NULL;
     1.9  	int width, height;
    1.10  	int maxval, y, bpl;
    1.11 @@ -121,6 +122,7 @@
    1.12  		/* The error message has been set in SDL_RWFromFile */
    1.13  		return NULL;
    1.14  	}
    1.15 +	start = SDL_RWtell(src);
    1.16  
    1.17  	SDL_RWread(src, magic, 2, 1);
    1.18  	kind = magic[1] - '1';
    1.19 @@ -229,9 +231,12 @@
    1.20  done:
    1.21  	free(buf);
    1.22  	if(error) {
    1.23 -		SDL_FreeSurface(surface);
    1.24 +		SDL_RWseek(src, start, SEEK_SET);
    1.25 +		if ( surface ) {
    1.26 +			SDL_FreeSurface(surface);
    1.27 +			surface = NULL;
    1.28 +		}
    1.29  		IMG_SetError(error);
    1.30 -		surface = NULL;
    1.31  	}
    1.32  	return(surface);
    1.33  }