Needed to allocate memory for the shadow surface if we needed to create one.
1.1 --- a/src/SDL_compat.c Wed Feb 16 01:26:39 2011 -0800
1.2 +++ b/src/SDL_compat.c Wed Feb 16 01:40:44 2011 -0800
1.3 @@ -847,14 +847,14 @@
1.4 }
1.5
1.6 /* Copy the old bits out */
1.7 - length = SDL_VideoSurface->w * SDL_VideoSurface->format->BytesPerPixel;
1.8 - pixels = SDL_malloc(SDL_VideoSurface->h * length);
1.9 + length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel;
1.10 + pixels = SDL_malloc(SDL_PublicSurface->h * length);
1.11 if (pixels) {
1.12 - src = (Uint8*)SDL_VideoSurface->pixels;
1.13 + src = (Uint8*)SDL_PublicSurface->pixels;
1.14 dst = (Uint8*)pixels;
1.15 - for (row = 0; row < SDL_VideoSurface->h; ++row) {
1.16 + for (row = 0; row < SDL_PublicSurface->h; ++row) {
1.17 SDL_memcpy(dst, src, length);
1.18 - src += SDL_VideoSurface->pitch;
1.19 + src += SDL_PublicSurface->pitch;
1.20 dst += length;
1.21 }
1.22 }
1.23 @@ -894,8 +894,8 @@
1.24 SDL_VideoSurface->flags &= ~SDL_DONTFREE;
1.25 SDL_FreeSurface(SDL_VideoSurface);
1.26 SDL_free(SDL_ShadowSurface->pixels);
1.27 - SDL_ShadowSurface->flags |= SDL_PREALLOC;
1.28 SDL_VideoSurface = SDL_ShadowSurface;
1.29 + SDL_VideoSurface->flags |= SDL_PREALLOC;
1.30 SDL_ShadowSurface = NULL;
1.31 } else {
1.32 /* No problem, just change the video surface format */
1.33 @@ -907,9 +907,18 @@
1.34 } else {
1.35 /* We can make the video surface the shadow surface */
1.36 SDL_ShadowSurface = SDL_VideoSurface;
1.37 + SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface);
1.38 + SDL_ShadowSurface->pixels = SDL_malloc(SDL_ShadowSurface->h * SDL_ShadowSurface->pitch);
1.39 + if (!SDL_ShadowSurface->pixels) {
1.40 + /* Uh oh, we're hosed */
1.41 + SDL_ShadowSurface = NULL;
1.42 + return 0;
1.43 + }
1.44 + SDL_ShadowSurface->flags &= ~SDL_PREALLOC;
1.45
1.46 SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0);
1.47 SDL_VideoSurface->flags = SDL_ShadowSurface->flags;
1.48 + SDL_VideoSurface->flags |= SDL_PREALLOC;
1.49 SDL_FreeFormat(SDL_VideoSurface->format);
1.50 SDL_VideoSurface->format = SDL_WindowSurface->format;
1.51 SDL_VideoSurface->format->refcount++;
1.52 @@ -928,13 +937,13 @@
1.53 /* Copy the old bits back */
1.54 if (pixels) {
1.55 src = (Uint8*)pixels;
1.56 - dst = (Uint8*)SDL_VideoSurface->pixels;
1.57 - for (row = 0; row < SDL_VideoSurface->h; ++row) {
1.58 + dst = (Uint8*)SDL_PublicSurface->pixels;
1.59 + for (row = 0; row < SDL_PublicSurface->h; ++row) {
1.60 SDL_memcpy(dst, src, length);
1.61 src += length;
1.62 - dst += SDL_VideoSurface->pitch;
1.63 + dst += SDL_PublicSurface->pitch;
1.64 }
1.65 - SDL_Flip(SDL_VideoSurface);
1.66 + SDL_Flip(SDL_PublicSurface);
1.67 SDL_free(pixels);
1.68 }
1.69