Skip to content

Commit

Permalink
Fixed a crash blitting RLE surfaces to RLE surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 11, 2002
1 parent a356201 commit 7812a4e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 64 deletions.
44 changes: 16 additions & 28 deletions src/video/SDL_RLEaccel.c
Expand Up @@ -463,18 +463,16 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect,
unsigned alpha;

/* Lock the destination if necessary */
if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if ( video->LockHWSurface(this, dst) < 0 ) {
if ( SDL_MUSTLOCK(dst) ) {
if ( SDL_LockSurface(dst) < 0 ) {
return(-1);
}
}

/* Set up the source and destination pointers */
x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *)dst->pixels + dst->offset
dstbuf = (Uint8 *)dst->pixels
+ y * dst->pitch + x * src->format->BytesPerPixel;
srcbuf = (Uint8 *)src->map->sw_data->aux_data;

Expand Down Expand Up @@ -553,10 +551,8 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect,

done:
/* Unlock the destination if necessary */
if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
video->UnlockHWSurface(this, dst);
if ( SDL_MUSTLOCK(dst) ) {
SDL_UnlockSurface(dst);
}
return(0);
}
Expand Down Expand Up @@ -733,17 +729,15 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_PixelFormat *df = dst->format;

/* Lock the destination if necessary */
if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if(video->LockHWSurface(this, dst) < 0) {
if ( SDL_MUSTLOCK(dst) ) {
if ( SDL_LockSurface(dst) < 0 ) {
return -1;
}
}

x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *)dst->pixels + dst->offset
dstbuf = (Uint8 *)dst->pixels
+ y * dst->pitch + x * df->BytesPerPixel;
srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat);

Expand Down Expand Up @@ -874,10 +868,8 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect,

done:
/* Unlock the destination if necessary */
if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
video->UnlockHWSurface(this, dst);
if ( SDL_MUSTLOCK(dst) ) {
SDL_UnlockSurface(dst);
}
return 0;
}
Expand Down Expand Up @@ -1117,7 +1109,7 @@ static int RLEAlphaSurface(SDL_Surface *surface)
int x, y;
int h = surface->h, w = surface->w;
SDL_PixelFormat *sf = surface->format;
Uint32 *src = (Uint32 *)((Uint8 *)surface->pixels + surface->offset);
Uint32 *src = (Uint32 *)surface->pixels;
Uint8 *lastline = dst; /* end of last non-blank line */

/* opaque counts are 8 or 16 bits, depending on target depth */
Expand Down Expand Up @@ -1303,7 +1295,7 @@ static int RLEColorkeySurface(SDL_Surface *surface)
}

/* Set up the conversion */
srcbuf = (Uint8 *)surface->pixels+surface->offset;
srcbuf = (Uint8 *)surface->pixels;
curbuf = srcbuf;
maxn = bpp == 4 ? 65535 : 255;
skip = run = 0;
Expand Down Expand Up @@ -1409,10 +1401,8 @@ int SDL_RLESurface(SDL_Surface *surface)
}

/* Lock the surface if it's in hardware */
if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if ( video->LockHWSurface(this, surface) < 0 ) {
if ( SDL_MUSTLOCK(surface) ) {
if ( SDL_LockSurface(surface) < 0 ) {
return(-1);
}
}
Expand All @@ -1429,10 +1419,8 @@ int SDL_RLESurface(SDL_Surface *surface)
}

/* Unlock the surface if it's in hardware */
if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
video->UnlockHWSurface(this, surface);
if ( SDL_MUSTLOCK(surface) ) {
SDL_UnlockSurface(surface);
}

if(retcode < 0)
Expand Down
36 changes: 8 additions & 28 deletions src/video/SDL_blit.c
Expand Up @@ -50,46 +50,36 @@ static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,

/* Lock the destination if it's in hardware */
dst_locked = 0;
if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if ( video->LockHWSurface(this, dst) < 0 ) {
if ( SDL_MUSTLOCK(dst) ) {
if ( SDL_LockSurface(dst) < 0 ) {
okay = 0;
} else {
dst_locked = 1;
}
}
/* Lock the source if it's in hardware */
src_locked = 0;
if ( src->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if ( video->LockHWSurface(this, src) < 0 ) {
if ( SDL_MUSTLOCK(src) ) {
if ( SDL_LockSurface(src) < 0 ) {
okay = 0;
} else {
src_locked = 1;
}
}

/* Unencode the destination if it's RLE encoded */
if ( dst->flags & SDL_RLEACCEL ) {
SDL_UnRLESurface(dst, 1);
dst->flags |= SDL_RLEACCEL; /* save accel'd state */
}

/* Set up source and destination buffer pointers, and BLIT! */
if ( okay && srcrect->w && srcrect->h ) {
SDL_BlitInfo info;
SDL_loblit RunBlit;

/* Set up the blit information */
info.s_pixels = (Uint8 *)src->pixels + src->offset +
info.s_pixels = (Uint8 *)src->pixels +
(Uint16)srcrect->y*src->pitch +
(Uint16)srcrect->x*src->format->BytesPerPixel;
info.s_width = srcrect->w;
info.s_height = srcrect->h;
info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel;
info.d_pixels = (Uint8 *)dst->pixels + dst->offset +
info.d_pixels = (Uint8 *)dst->pixels +
(Uint16)dstrect->y*dst->pitch +
(Uint16)dstrect->x*dst->format->BytesPerPixel;
info.d_width = dstrect->w;
Expand All @@ -105,22 +95,12 @@ static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
RunBlit(&info);
}

/* Re-encode the destination if it's RLE encoded */
if ( dst->flags & SDL_RLEACCEL ) {
dst->flags &= ~SDL_RLEACCEL; /* stop lying */
SDL_RLESurface(dst);
}

/* We need to unlock the surfaces if they're locked */
if ( dst_locked ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
video->UnlockHWSurface(this, dst);
SDL_UnlockSurface(dst);
}
if ( src_locked ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
video->UnlockHWSurface(this, src);
SDL_UnlockSurface(src);
}
/* Blit is done! */
return(okay ? 0 : -1);
Expand Down
8 changes: 0 additions & 8 deletions src/video/SDL_surface.c
Expand Up @@ -692,10 +692,6 @@ int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)

/*
* Lock a surface to directly access the pixels
* -- Do not call this from any blit function, as SDL_DrawCursor() may recurse
* Instead, use:
* if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )
* video->LockHWSurface(video, surface);
*/
int SDL_LockSurface (SDL_Surface *surface)
{
Expand Down Expand Up @@ -724,10 +720,6 @@ int SDL_LockSurface (SDL_Surface *surface)
}
/*
* Unlock a previously locked surface
* -- Do not call this from any blit function, as SDL_DrawCursor() may recurse
* Instead, use:
* if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )
* video->UnlockHWSurface(video, surface);
*/
void SDL_UnlockSurface (SDL_Surface *surface)
{
Expand Down

0 comments on commit 7812a4e

Please sign in to comment.