engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
authorMedo <smaxein@googlemail.com>
Sat, 18 Aug 2012 13:21:37 +0200
changeset 7556 4617e8ec0507
parent 7554 e50b266ed85a
child 7558 983ff426f91e
engine: Fixed sigsegv on android caused by modifying Template.FillPoints constants
hedgewars/uLand.pas
hedgewars/uLandTemplates.pas
--- a/hedgewars/uLand.pas	Sat Aug 18 01:20:29 2012 +0200
+++ b/hedgewars/uLand.pas	Sat Aug 18 13:21:37 2012 +0200
@@ -127,7 +127,7 @@
     SDL_FreeSurface(tmpsurf);
 end;
 
-procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr);
+procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr; fps: PPointArray);
 var i: LongInt;
 begin
 with Template do
@@ -148,7 +148,7 @@
                if pa.ar[i].x <> NTPX then
                    pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x;
             for i:= 0 to pred(FillPointsCount) do
-                FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x;
+                fps^[i].x:= LAND_WIDTH - 1 - fps^[i].x;
             end;
 
 (*  Experiment in making this option more useful
@@ -181,9 +181,9 @@
             end;
         for i:= 0 to pred(FillPointsCount) do
             begin
-            dec(FillPoints^[i].y, 100);
-            if FillPoints^[i].y < 0 then
-                FillPoints^[i].y:= 0;
+            dec(fps^[i].y, 100);
+            if fps^[i].y < 0 then
+                fps^[i].y:= 0;
             end;
         end;
 
@@ -192,7 +192,7 @@
         for i:= 0 to pred(BasePointsCount) do
             pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y;
         for i:= 0 to pred(FillPointsCount) do
-            FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y;
+            fps^[i].y:= LAND_HEIGHT - 1 - fps^[i].y;
         end;
     end
 end;
@@ -202,13 +202,15 @@
 var pa: TPixAr;
     i: Longword;
     y, x: Longword;
+	fps: TPointArray;
 begin
+	fps:=Template.FillPoints^;
     ResizeLand(Template.TemplateWidth, Template.TemplateHeight);
     for y:= 0 to LAND_HEIGHT - 1 do
         for x:= 0 to LAND_WIDTH - 1 do
             Land[y, x]:= lfBasic;
     {$HINTS OFF}
-    SetPoints(Template, pa);
+    SetPoints(Template, pa, @fps);
     {$HINTS ON}
     for i:= 1 to Template.BezierizeCount do
         begin
@@ -225,7 +227,7 @@
 
     with Template do
         for i:= 0 to pred(FillPointsCount) do
-            with FillPoints^[i] do
+            with fps[i] do
                 FillLand(x, y);
 
     DrawEdge(pa, lfBasic);
--- a/hedgewars/uLandTemplates.pas	Sat Aug 18 01:20:29 2012 +0200
+++ b/hedgewars/uLandTemplates.pas	Sat Aug 18 13:21:37 2012 +0200
@@ -24,10 +24,12 @@
 
 const NTPX = Low(SmallInt);
 
-type TPointArray = array[0..64] of TSDL_Rect;
+type TRectArray = array[0..64] of TSDL_Rect;
+     PRectArray = ^TRectArray;
+	 TPointArray = array[0..64] of TPoint;
      PPointArray = ^TPointArray;
      TEdgeTemplate = record
-                     BasePoints: PPointArray;
+                     BasePoints: PRectArray;
                      BasePointsCount: Longword;
                      FillPoints: PPointArray;
                      FillPointsCount: Longword;