initialize pointers properly with nil
authorsheepluva
Sun, 06 Feb 2011 00:47:00 +0100
changeset 4925 3d90fd7f738a
parent 4924 616b618814b5
child 4926 f9a13dd16f01
initialize pointers properly with nil
hedgewars/uChat.pas
hedgewars/uStore.pas
--- a/hedgewars/uChat.pas	Sat Feb 05 22:22:16 2011 +0100
+++ b/hedgewars/uChat.pas	Sun Feb 06 00:47:00 2011 +0100
@@ -65,9 +65,8 @@
     color: TSDL_Color;
     font: THWFont;
 begin
-// these two lines lines crash when run multiple times?
-//if cl.Tex <> nil then
-//    FreeTexture(cl.Tex);
+if cl.Tex <> nil then
+    FreeTexture(cl.Tex);
 
 cl.s:= str;
 
@@ -355,6 +354,7 @@
 end;
 
 procedure initModule;
+var i: ShortInt;
 begin
     RegisterVariable('chatmsg', vtCommand, @chChatMessage, true);
     RegisterVariable('say', vtCommand, @chSay, true);
@@ -367,6 +367,12 @@
     showAll:= false;
     ChatReady:= false;
     missedCount:= 0;
+
+    inputStr.Tex := nil;
+    for i:= 0 to MaxStrIndex do
+    begin
+        Strs[i].Tex := nil;
+    end;
 end;
 
 procedure freeModule;
--- a/hedgewars/uStore.pas	Sat Feb 05 22:22:16 2011 +0100
+++ b/hedgewars/uStore.pas	Sun Feb 06 00:47:00 2011 +0100
@@ -343,9 +343,8 @@
         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
         TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
         tmpsurf:= doSurfaceConversion(tmpsurf);
-        // these two lines lines crash when run multiple times?
-        //if (NameTex <> nil) then
-        //    FreeTexture(NameTex);
+        if (NameTex <> nil) then
+            FreeTexture(NameTex);
         NameTex:= Surface2Tex(tmpsurf, false);
         SDL_FreeSurface(tmpsurf)
     end;
@@ -355,9 +354,8 @@
 begin
     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
     tmpsurf:= doSurfaceConversion(tmpsurf);
-    // these two lines lines crash when run multiple times?
-    //if (CountTexz[i] <> nil) then
-    //    FreeTexture(CountTexz[i]);
+    if (CountTexz[i] <> nil) then
+        FreeTexture(CountTexz[i]);
     CountTexz[i]:= Surface2Tex(tmpsurf, false);
     SDL_FreeSurface(tmpsurf)
 end;
@@ -951,6 +949,8 @@
 end;
 
 procedure initModule;
+var ai: TAmmoType;
+    i: LongInt;
 begin
     RegisterVariable('fullscr', vtCommand, @chFullScr, true);
 
@@ -966,6 +966,17 @@
     SupportNPOTT:= false;
     Step:= 0;
     ProgrTex:= nil;
+
+    // init all ammo name texture pointers
+    for ai:= Low(TAmmoType) to High(TAmmoType) do
+    begin
+        Ammoz[ai].NameTex := nil;
+    end;
+    // init all count texture pointers
+    for i:= Low(CountTexz) to High(CountTexz) do
+    begin
+        CountTexz[i] := nil;
+    end;
 end;
 
 procedure freeModule;