DEADSOFTWARE

gl: fix crash on render finalization
[d2df-sdl.git] / src / game / renders / opengl / r_textures.pas
index f66708fbe57af0a95b177e3ba078d5d366c40877..97d572c5776b02fac7f16af63070b832cc4933c0 100644 (file)
@@ -492,9 +492,12 @@ implementation
     begin
       for i := 0 to High(atl) do
       begin
-        glDeleteTextures(1, @atl[i].id);
-        atl[i].id := 0;
-        r_Common_FreeAndNil(atl[i]);
+        if atl[i] <> nil then
+        begin
+          glDeleteTextures(1, @atl[i].id);
+          atl[i].id := 0;
+          r_Common_FreeAndNil(atl[i]);
+        end;
       end;
     end;
     SetLength(atl, 0);
@@ -503,9 +506,12 @@ implementation
     begin
       for i := 0 to High(ratl) do
       begin
-        glDeleteTextures(1, @ratl[i].id);
-        ratl[i].id := 0;
-        r_Common_FreeAndNil(ratl[i]);
+        if ratl[i] <> nil then
+        begin
+          glDeleteTextures(1, @ratl[i].id);
+          ratl[i].id := 0;
+          r_Common_FreeAndNil(ratl[i]);
+        end;
       end;
     end;
     SetLength(ratl, 0);
@@ -644,8 +650,8 @@ implementation
     end;
   end;
 
-  function r_Textures_LoadTextFromMemory (data: Pointer; size: LongInt; var txt: TAnimTextInfo): Boolean;
-    var cfg: TConfig; text: TAnimTextInfo;
+  function r_Textures_LoadTextFromMemory (data: Pointer; size: LongInt; var text: TAnimTextInfo): Boolean;
+    var cfg: TConfig;
   begin
     result := false;
     if data <> nil then
@@ -669,11 +675,7 @@ implementation
         text.anim.delay := MAX(1, text.anim.delay);
         text.anim.frames := MAX(1, text.anim.frames);
         cfg.Free;
-        if (txt.name <> '') and (txt.w > 0) and (txt.h > 0) and (txt.anim.delay > 0) and (txt.anim.frames > 0) then
-        begin
-          txt := text;
-          result := true;
-        end;
+        result := (text.name <> '') and (text.w > 0) and (text.h > 0) and (text.anim.delay > 0) and (text.anim.frames > 0);
       end;
     end;
   end;