# HG changeset patch
# User Urbertar@gmail.com
# Date 1361867271 -7200
# Node ID f3bc24ef756e5e59a7f880c0684b53317423ed8b
# Parent  7fa0f75bce57ea05b1cd58b246e856316b995906
Check bounds of landscape in drawice procedure

diff -r 7fa0f75bce57 -r f3bc24ef756e hedgewars/GSHandlers.inc
--- a/hedgewars/GSHandlers.inc	Mon Feb 25 20:45:13 2013 -0500
+++ b/hedgewars/GSHandlers.inc	Tue Feb 26 10:27:51 2013 +0200
@@ -5159,8 +5159,8 @@
 var
     i, j: Longint;
     weight: Longint;
-begin    
-
+    landRect : TSDL_RECT;
+begin
     for i := max(x - iceHalfSize, 0) to min(x + iceHalfSize, LAND_WIDTH-1) do
         begin
         for j := max(y - iceHalfSize, 0) to min(y + iceHalfSize, LAND_HEIGHT-1) do 
@@ -5181,7 +5181,11 @@
             end;
         end;
     SetAllHHToActive; 
-    UpdateLandTexture(x - iceHalfSize, iceSize, y - iceHalfSize, iceSize, true);
+    landRect.x := min(max(x - iceHalfSize, 0), LAND_WIDTH - 1);
+    landRect.y := min(max(y - iceHalfSize, 0), LAND_HEIGHT - 1);
+    landRect.w := min(iceSize, LAND_WIDTH - landRect.x - 1);
+    landRect.h := min(iceSize, LAND_HEIGHT - landRect.y - 1);
+    UpdateLandTexture(landRect.x, landRect.w, landRect.y, landRect.h, true);
 end;