Commit f410c37f authored by Sam Lantinga's avatar Sam Lantinga

Don't crash if the stretch routines are used on hardware surfaces

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40895
parent fd0bae8c
...@@ -181,6 +181,8 @@ void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w) ...@@ -181,6 +181,8 @@ void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w)
int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect) SDL_Surface *dst, SDL_Rect *dstrect)
{ {
int src_locked;
int dst_locked;
int pos, inc; int pos, inc;
int dst_width; int dst_width;
int dst_maxrow; int dst_maxrow;
...@@ -229,6 +231,28 @@ int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, ...@@ -229,6 +231,28 @@ int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
dstrect = &full_dst; dstrect = &full_dst;
} }
/* Lock the destination if it's in hardware */
dst_locked = 0;
if ( SDL_MUSTLOCK(dst) ) {
if ( SDL_LockSurface(dst) < 0 ) {
SDL_SetError("Unable to lock destination surface");
return(-1);
}
dst_locked = 1;
}
/* Lock the source if it's in hardware */
src_locked = 0;
if ( SDL_MUSTLOCK(src) ) {
if ( SDL_LockSurface(src) < 0 ) {
if ( dst_locked ) {
SDL_UnlockSurface(dst);
}
SDL_SetError("Unable to lock source surface");
return(-1);
}
src_locked = 1;
}
/* Set up the data... */ /* Set up the data... */
pos = 0x10000; pos = 0x10000;
inc = (srcrect->h << 16) / dstrect->h; inc = (srcrect->h << 16) / dstrect->h;
...@@ -307,6 +331,14 @@ int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, ...@@ -307,6 +331,14 @@ int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
#endif #endif
pos += inc; pos += inc;
} }
/* We need to unlock the surfaces if they're locked */
if ( dst_locked ) {
SDL_UnlockSurface(dst);
}
if ( src_locked ) {
SDL_UnlockSurface(src);
}
return(0); return(0);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment