Don't crash if the stretch routines are used on hardware surfaces
authorSam Lantinga <slouken@libsdl.org>
Sun, 16 May 2004 21:08:55 +0000
changeset 8941d1a823904d8
parent 893 8762a202f121
child 895 ec659230eaac
Don't crash if the stretch routines are used on hardware surfaces
src/video/SDL_stretch.c
     1.1 --- a/src/video/SDL_stretch.c	Sun May 16 19:02:19 2004 +0000
     1.2 +++ b/src/video/SDL_stretch.c	Sun May 16 21:08:55 2004 +0000
     1.3 @@ -181,6 +181,8 @@
     1.4  int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
     1.5                      SDL_Surface *dst, SDL_Rect *dstrect)
     1.6  {
     1.7 +	int src_locked;
     1.8 +	int dst_locked;
     1.9  	int pos, inc;
    1.10  	int dst_width;
    1.11  	int dst_maxrow;
    1.12 @@ -229,6 +231,28 @@
    1.13  		dstrect = &full_dst;
    1.14  	}
    1.15  
    1.16 +	/* Lock the destination if it's in hardware */
    1.17 +	dst_locked = 0;
    1.18 +	if ( SDL_MUSTLOCK(dst) ) {
    1.19 +		if ( SDL_LockSurface(dst) < 0 ) {
    1.20 +			SDL_SetError("Unable to lock destination surface");
    1.21 +			return(-1);
    1.22 +		}
    1.23 +		dst_locked = 1;
    1.24 +	}
    1.25 +	/* Lock the source if it's in hardware */
    1.26 +	src_locked = 0;
    1.27 +	if ( SDL_MUSTLOCK(src) ) {
    1.28 +		if ( SDL_LockSurface(src) < 0 ) {
    1.29 +			if ( dst_locked ) {
    1.30 +				SDL_UnlockSurface(dst);
    1.31 +			}
    1.32 +			SDL_SetError("Unable to lock source surface");
    1.33 +			return(-1);
    1.34 +		}
    1.35 +		src_locked = 1;
    1.36 +	}
    1.37 +
    1.38  	/* Set up the data... */
    1.39  	pos = 0x10000;
    1.40  	inc = (srcrect->h << 16) / dstrect->h;
    1.41 @@ -307,6 +331,14 @@
    1.42  #endif
    1.43  		pos += inc;
    1.44  	}
    1.45 +
    1.46 +	/* We need to unlock the surfaces if they're locked */
    1.47 +	if ( dst_locked ) {
    1.48 +		SDL_UnlockSurface(dst);
    1.49 +	}
    1.50 +	if ( src_locked ) {
    1.51 +		SDL_UnlockSurface(src);
    1.52 +	}
    1.53  	return(0);
    1.54  }
    1.55