rnd-20080802-1-src
[rocksndiamonds.git] / src / libgame / system.c
index ed856965d6ab7f6fce783f97c8c7414b78426072..20ea20bed03553ee0e76107830f8dc3031045e41 100644 (file)
@@ -384,16 +384,18 @@ Bitmap *CreateBitmapStruct(void)
 Bitmap *CreateBitmap(int width, int height, int depth)
 {
   Bitmap *new_bitmap = CreateBitmapStruct();
-  int real_depth = GetRealDepth(depth);
+  int real_width  = MAX(1, width);     /* prevent zero bitmap width */
+  int real_height = MAX(1, height);    /* prevent zero bitmap height */
+  int real_depth  = GetRealDepth(depth);
 
 #if defined(TARGET_SDL)
-  SDLCreateBitmapContent(new_bitmap, width, height, real_depth);
+  SDLCreateBitmapContent(new_bitmap, real_width, real_height, real_depth);
 #else
-  X11CreateBitmapContent(new_bitmap, width, height, real_depth);
+  X11CreateBitmapContent(new_bitmap, real_width, real_height, real_depth);
 #endif
 
-  new_bitmap->width width;
-  new_bitmap->height = height;
+  new_bitmap->width  = real_width;
+  new_bitmap->height = real_height;
 
   return new_bitmap;
 }
@@ -489,8 +491,34 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
   if (DrawingDeactivated(dst_x, dst_y, width, height))
     return;
 
-  sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
-             dst_x, dst_y, BLIT_OPAQUE);
+#if 0
+  /* !!! APPARENTLY THIS HAS BEEN FIXED IN SDL 1.2.12 !!! */
+#if defined(TARGET_SDL) && defined(PLATFORM_WIN32)
+  if (src_bitmap == dst_bitmap)
+  {
+    /* !!! THIS IS A BUG (IN THE SDL LIBRARY?) AND SHOULD BE FIXED !!! */
+
+    /* needed when blitting directly to same bitmap -- should not be needed with
+       recent SDL libraries, but apparently does not work in 1.2.11 directly */
+
+    static Bitmap *tmp_bitmap = NULL;
+
+    if (tmp_bitmap == NULL)
+      tmp_bitmap = CreateBitmap(MAX(FXSIZE, WIN_XSIZE),
+                               MAX(FYSIZE, WIN_YSIZE), DEFAULT_DEPTH);
+
+    sysCopyArea(src_bitmap, tmp_bitmap,
+               src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE);
+    sysCopyArea(tmp_bitmap, dst_bitmap,
+               src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE);
+
+    return;
+  }
+#endif
+#endif
+
+  sysCopyArea(src_bitmap, dst_bitmap,
+             src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE);
 }
 
 void FadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,