(svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
authortruelight
Wed, 29 Aug 2007 21:30:03 +0000
changeset 7985 c7b966f7592e
parent 7984 c539c9368e3c
child 7986 881998b115c2
(svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
-Note: we no longer cheat on not drawing the last line in smallmap, this time we created a more elegant fix
src/smallmap_gui.cpp
--- a/src/smallmap_gui.cpp	Wed Aug 29 21:27:16 2007 +0000
+++ b/src/smallmap_gui.cpp	Wed Aug 29 21:30:03 2007 +0000
@@ -169,28 +169,6 @@
 	_legend_land_owners,
 };
 
-static inline void WRITE_PIXELS(void *d, uint32 val)
-{
-	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
-	uint8 *val8 = (uint8 *)&val;
-
-	blitter->SetPixel(d, 0, 0, val8[0]);
-	blitter->SetPixel(d, 1, 0, val8[1]);
-	blitter->SetPixel(d, 2, 0, val8[2]);
-	blitter->SetPixel(d, 3, 0, val8[3]);
-}
-
-static inline void WRITE_PIXELS_OR(void *d, uint32 val)
-{
-	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
-	uint8 *val8 = (uint8 *)&val;
-
-	blitter->SetPixelIfEmpty(d, 0, 0, val8[0]);
-	blitter->SetPixelIfEmpty(d, 1, 0, val8[1]);
-	blitter->SetPixelIfEmpty(d, 2, 0, val8[2]);
-	blitter->SetPixelIfEmpty(d, 3, 0, val8[3]);
-}
-
 #define MKCOLOR(x) TO_LE32X(x)
 
 /**
@@ -290,14 +268,31 @@
 static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
 {
 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
-	void *dst_ptr_end = blitter->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
+	void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height);
+	void *dst_ptr_end = blitter->MoveTo(dst_ptr_abs_end, -4, 0);
 
 	do {
 		/* check if the tile (xc,yc) is within the map range */
 		if (xc < MapMaxX() && yc < MapMaxY()) {
 			/* check if the dst pointer points to a pixel inside the screen buffer */
-			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
-				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
+			if (dst < _screen.dst_ptr) continue;
+			if (dst >= dst_ptr_abs_end) continue;
+
+			uint32 val = proc(TileXY(xc, yc)) & mask;
+			uint8 *val8 = (uint8 *)&val;
+
+			if (dst <= dst_ptr_end) {
+				blitter->SetPixelIfEmpty(dst, 0, 0, val8[0]);
+				blitter->SetPixelIfEmpty(dst, 1, 0, val8[1]);
+				blitter->SetPixelIfEmpty(dst, 2, 0, val8[2]);
+				blitter->SetPixelIfEmpty(dst, 3, 0, val8[3]);
+			} else {
+				/* It happens that there are only 1, 2 or 3 pixels left to fill, so in that special case, write till the end of the video-buffer */
+				int i = 0;
+				do {
+					blitter->SetPixelIfEmpty(dst, 0, 0, val8[i]);
+				} while (i++, dst = blitter->MoveTo(dst, 1, 0), dst < dst_ptr_abs_end);
+			}
 		}
 	/* switch to next tile in the column */
 	} while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);