DEADSOFTWARE

simple allocation counter for classes
[d2df-sdl.git] / src / game / g_gui.pas
index d7735ab374d568a4e51cf47c543f1a2c458d7522..2ead3bbbb06a9e0bf0bd7c8cbae0b5eb2d626919 100644 (file)
@@ -19,6 +19,7 @@ unit g_gui;
 interface
 
 uses
+  mempool,
   e_graphics, e_input, e_log, g_playermodel, g_basic, MAPDEF, wadreader;
 
 const
@@ -84,7 +85,7 @@ type
 
   TFontType = (FONT_TEXTURE, FONT_CHAR);
 
-  TFont = class(TObject)
+  TFont = class(TPoolObject)
   private
     ID: DWORD;
     FScale: Single;
@@ -108,7 +109,7 @@ type
   TOnChangeEvent = procedure(Sender: TGUIControl);
   TOnEnterEvent = procedure(Sender: TGUIControl);
 
-  TGUIControl = class
+  TGUIControl = class(TPoolObject)
   private
     FX, FY: Integer;
     FEnabled: Boolean;
@@ -133,7 +134,7 @@ type
     property RightAlign: Boolean read FRightAlign write FRightAlign; // for menu
   end;
 
-  TGUIWindow = class
+  TGUIWindow = class(TPoolObject)
   private
     FActiveControl: TGUIControl;
     FDefControl: string;
@@ -416,7 +417,7 @@ type
     property Font: TFont read FFont write FFont;
   end;
 
-  TGUIFileListBox = class (TGUIListBox)
+  TGUIFileListBox = class(TGUIListBox)
   private
     FBasePath: String;
     FPath: String;
@@ -2810,61 +2811,68 @@ begin
   try
     map := g_Map_ParseMap(Data, Len);
   except
+    FreeMem(Data);
     map.Free();
-    raise;
+    //raise;
+    exit;
   end;
 
   FreeMem(Data);
 
-  panlist := map.field['panel'];
-  //header := GetMapHeader(map);
+  if (map = nil) then exit;
 
-  FMapSize.X := map.Width div 16;
-  FMapSize.Y := map.Height div 16;
+  try
+    panlist := map.field['panel'];
+    //header := GetMapHeader(map);
 
-  rX := Ceil(map.Width / (MAPPREVIEW_WIDTH*256.0));
-  rY := Ceil(map.Height / (MAPPREVIEW_HEIGHT*256.0));
-  FScale := max(rX, rY);
+    FMapSize.X := map.Width div 16;
+    FMapSize.Y := map.Height div 16;
 
-  FMapData := nil;
+    rX := Ceil(map.Width / (MAPPREVIEW_WIDTH*256.0));
+    rY := Ceil(map.Height / (MAPPREVIEW_HEIGHT*256.0));
+    FScale := max(rX, rY);
 
-  if (panlist <> nil) then
-  begin
-    for pan in panlist do
+    FMapData := nil;
+
+    if (panlist <> nil) then
     begin
-      if (pan.PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or
-                                           PANEL_STEP or PANEL_WATER or
-                                           PANEL_ACID1 or PANEL_ACID2)) <> 0 then
+      for pan in panlist do
       begin
-        SetLength(FMapData, Length(FMapData)+1);
-        with FMapData[High(FMapData)] do
+        if (pan.PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or
+                                             PANEL_STEP or PANEL_WATER or
+                                             PANEL_ACID1 or PANEL_ACID2)) <> 0 then
         begin
-          X1 := pan.X div 16;
-          Y1 := pan.Y div 16;
+          SetLength(FMapData, Length(FMapData)+1);
+          with FMapData[High(FMapData)] do
+          begin
+            X1 := pan.X div 16;
+            Y1 := pan.Y div 16;
 
-          X2 := (pan.X + pan.Width) div 16;
-          Y2 := (pan.Y + pan.Height) div 16;
+            X2 := (pan.X + pan.Width) div 16;
+            Y2 := (pan.Y + pan.Height) div 16;
 
-          X1 := Trunc(X1/FScale + 0.5);
-          Y1 := Trunc(Y1/FScale + 0.5);
-          X2 := Trunc(X2/FScale + 0.5);
-          Y2 := Trunc(Y2/FScale + 0.5);
+            X1 := Trunc(X1/FScale + 0.5);
+            Y1 := Trunc(Y1/FScale + 0.5);
+            X2 := Trunc(X2/FScale + 0.5);
+            Y2 := Trunc(Y2/FScale + 0.5);
 
-          if (X1 <> X2) or (Y1 <> Y2) then
-          begin
-            if X1 = X2 then
-              X2 := X2 + 1;
-            if Y1 = Y2 then
-              Y2 := Y2 + 1;
-          end;
+            if (X1 <> X2) or (Y1 <> Y2) then
+            begin
+              if X1 = X2 then
+                X2 := X2 + 1;
+              if Y1 = Y2 then
+                Y2 := Y2 + 1;
+            end;
 
-          PanelType := pan.PanelType;
+            PanelType := pan.PanelType;
+          end;
         end;
       end;
     end;
+  finally
+    //writeln('freeing map');
+    map.Free();
   end;
-
-  map.Free();
 end;
 
 procedure TGUIMapPreview.ClearMap();