From a134fea46c5760c78cacba16ff32f1b748e3e643 Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Sat, 13 Mar 2004 19:48:07 +0000
Subject: [PATCH] Removed CompressedGraphicMemory, Fixed memory leak

---
 src/game/game.cpp     | 4 ----
 src/include/video.h   | 1 -
 src/video/graphic.cpp | 3 ++-
 src/video/sprite.cpp  | 7 ++-----
 src/video/video.cpp   | 1 -
 5 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/src/game/game.cpp b/src/game/game.cpp
index 879a4ee7f..95cb51172 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -457,10 +457,6 @@ global void CreateGame(char* filename, WorldMap* map)
 		AllocatedGraphicMemory _C_
 		AllocatedGraphicMemory / 1024 _C_
 		AllocatedGraphicMemory / 1024 / 1024);
-	DebugLevel0("Compressed graphics uses %d bytes (%d KB, %d MB)\n" _C_
-		CompressedGraphicMemory _C_
-		CompressedGraphicMemory / 1024 _C_
-		CompressedGraphicMemory / 1024 / 1024);
 
 	CreateMinimap();   // create minimap for pud
 	InitMap();         // setup draw functions
diff --git a/src/include/video.h b/src/include/video.h
index 56d58dea4..b54028872 100644
--- a/src/include/video.h
+++ b/src/include/video.h
@@ -66,7 +66,6 @@ typedef struct _unit_colors_ {
 
 #ifdef DEBUG
 extern unsigned AllocatedGraphicMemory;		/// Allocated memory for objects
-extern unsigned CompressedGraphicMemory;/// memory for compressed objects
 #endif
 
 /**
diff --git a/src/video/graphic.cpp b/src/video/graphic.cpp
index caf07eea1..79ff8a2d2 100644
--- a/src/video/graphic.cpp
+++ b/src/video/graphic.cpp
@@ -512,7 +512,7 @@ global void MakePlayerColorTexture(Graphic** g, Graphic* graphic, int frame,
 **  @todo FIXME: Higher quality resizing.
 **        FIXME: Works only with 8bit indexed graphic objects.
 */
-global void ResizeGraphic(Graphic *g, int w, int h)
+global void ResizeGraphic(Graphic* g, int w, int h)
 {
 	int i;
 	int j;
@@ -553,6 +553,7 @@ global void ResizeGraphic(Graphic *g, int w, int h)
 
 	g->Width = w;
 	g->Height = h;
+	free(g->Data);
 	g->Data = data;
 }
 
diff --git a/src/video/sprite.cpp b/src/video/sprite.cpp
index fb8ee5ca9..933f0ca07 100644
--- a/src/video/sprite.cpp
+++ b/src/video/sprite.cpp
@@ -420,17 +420,14 @@ global Graphic* LoadSprite(const char* name, int width, int height)
 
 	DebugCheck(width > g->Width || height > g->Height);
 
-	if (!width || !height || (g->Width / width) * width != g->Width ||
+	if ((g->Width / width) * width != g->Width ||
 			(g->Height / height) * height != g->Height) {
 		fprintf(stderr, "Invalid graphic (width, height) %s\n", name);
 		fprintf(stderr, "Expected: (%d,%d)  Found: (%d,%d)\n",
 			width, height, g->Width, g->Height);
+		ExitFatal(1);
 	}
 
-	// Check if width and height fits.
-	DebugCheck((g->Width / width) * width != g->Width ||
-		(g->Height / height) * height != g->Height);
-
 #ifdef USE_OPENGL
 	MakeTexture(g, width, height);
 	g->GraphicWidth = g->Width;
diff --git a/src/video/video.cpp b/src/video/video.cpp
index 23a7d9d30..fe65d082d 100644
--- a/src/video/video.cpp
+++ b/src/video/video.cpp
@@ -153,7 +153,6 @@ local Clip* ClipsGarbage;				/// garbage-list of available clips
 
 #ifdef DEBUG
 global unsigned AllocatedGraphicMemory; /// Allocated memory for objects
-global unsigned CompressedGraphicMemory;/// memory for compressed objects
 #endif
 
 	/**