]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_textures.c
Added a test when freeing textures (glt->image can be NULL if the program exits becau...
[xonotic/darkplaces.git] / gl_textures.c
index 558b1f59cb457bfab6721dec5a539c06e0e5c99e..edd0b7dbac9ba494ea1774fe31567f2ca819c61f 100644 (file)
@@ -222,20 +222,23 @@ void R_FreeTexture(rtexture_t *rt)
        // note: if freeing a fragment texture, this will not make the claimed
        // space available for new textures unless all other fragments in the
        // image are also freed
-       image = glt->image;
-       image->texturecount--;
-       if (image->texturecount < 1)
+       if (glt->image)
        {
-               for (gltimagepointer = &glt->pool->imagechain;*gltimagepointer && *gltimagepointer != image;gltimagepointer = &(*gltimagepointer)->imagechain);
-               if (*gltimagepointer == image)
-                       *gltimagepointer = image->imagechain;
-               else
-                       Host_Error("R_FreeTexture: image not linked in pool\n");
-               if (image->texnum)
-                       qglDeleteTextures(1, &image->texnum);
-               if (image->blockallocation)
-                       Mem_Free(image->blockallocation);
-               Mem_Free(image);
+               image = glt->image;
+               image->texturecount--;
+               if (image->texturecount < 1)
+               {
+                       for (gltimagepointer = &glt->pool->imagechain;*gltimagepointer && *gltimagepointer != image;gltimagepointer = &(*gltimagepointer)->imagechain);
+                       if (*gltimagepointer == image)
+                               *gltimagepointer = image->imagechain;
+                       else
+                               Host_Error("R_FreeTexture: image not linked in pool\n");
+                       if (image->texnum)
+                               qglDeleteTextures(1, &image->texnum);
+                       if (image->blockallocation)
+                               Mem_Free(image->blockallocation);
+                       Mem_Free(image);
+               }
        }
 
        if (glt->identifier)