From c53d916981cc4c17b1ea39c4b98c822cc9f53c4c Mon Sep 17 00:00:00 2001
From: johns <>
Date: Mon, 29 Jul 2002 19:09:40 +0000
Subject: [PATCH] Fixed crash from last change.

---
 src/video/font.cpp | 97 ++++++++++++++++++++++++++--------------------
 1 file changed, 56 insertions(+), 41 deletions(-)

diff --git a/src/video/font.cpp b/src/video/font.cpp
index 9a18d0cea..73db093ef 100644
--- a/src/video/font.cpp
+++ b/src/video/font.cpp
@@ -698,9 +698,11 @@ global void LoadFonts(void)
     }
 
     for( i=0; i<sizeof(Fonts)/sizeof(*Fonts); ++i ) {
-	ShowLoadProgress("\tFonts %s\n",Fonts[i].File);
-	Fonts[i].Graphic=LoadGraphic(Fonts[i].File);
-	FontMeasureWidths(Fonts+i);
+	if( Fonts[i].File ) {
+	    ShowLoadProgress("\tFonts %s\n",Fonts[i].File);
+	    Fonts[i].Graphic=LoadGraphic(Fonts[i].File);
+	    FontMeasureWidths(Fonts+i);
+	}
     }
 }
 
@@ -710,6 +712,41 @@ global void LoadFonts(void)
 
 #include "ccl.h"
 
+/**
+**	Font symbol to id.
+**
+**	@param type	Type of the font (game,small,...)
+**
+**	@return		Integer as font identifier.
+*/
+global int CclFontByIdentifier(SCM type)
+{
+    if (gh_eq_p(type, gh_symbol2scm("game"))) {
+	return GameFont;
+    } else if (gh_eq_p(type, gh_symbol2scm("small"))) {
+	return SmallFont;
+    } else if (gh_eq_p(type, gh_symbol2scm("large"))) {
+	return LargeFont;
+    } else if (gh_eq_p(type, gh_symbol2scm("small-title"))) {
+	return SmallTitleFont;
+    } else if (gh_eq_p(type, gh_symbol2scm("large-title"))) {
+	return LargeTitleFont;
+    } else if (gh_eq_p(type, gh_symbol2scm("user1"))) {
+	return User1Font;
+    } else if (gh_eq_p(type, gh_symbol2scm("user2"))) {
+	return User2Font;
+    } else if (gh_eq_p(type, gh_symbol2scm("user3"))) {
+	return User3Font;
+    } else if (gh_eq_p(type, gh_symbol2scm("user4"))) {
+	return User4Font;
+    } else if (gh_eq_p(type, gh_symbol2scm("user5"))) {
+	return User5Font;
+    } else {
+	errl("Unsupported font tag", type);
+    }
+    return 0;
+}
+
 /**
 **	Define the used fonts.
 **
@@ -720,39 +757,17 @@ global void LoadFonts(void)
 **
 **	@todo	make the font name functions more general, support more fonts.
 */
-local SCM CclDefineFont(SCM type,SCM file,SCM width,SCM height)
+local SCM CclDefineFont(SCM type, SCM file, SCM width, SCM height)
 {
     int i;
 
-    if( gh_eq_p(type,gh_symbol2scm("game")) ) {
-	i=GameFont;
-    } else if( gh_eq_p(type,gh_symbol2scm("small")) ) {
-	i=SmallFont;
-    } else if( gh_eq_p(type,gh_symbol2scm("large")) ) {
-	i=LargeFont;
-    } else if( gh_eq_p(type,gh_symbol2scm("small-title")) ) {
-	i=SmallTitleFont;
-    } else if( gh_eq_p(type,gh_symbol2scm("large-title")) ) {
-	i=LargeTitleFont;
-    } else if( gh_eq_p(type,gh_symbol2scm("user1")) ) {
-	i=User1Font;
-    } else if( gh_eq_p(type,gh_symbol2scm("user2")) ) {
-	i=User2Font;
-    } else if( gh_eq_p(type,gh_symbol2scm("user3")) ) {
-	i=User3Font;
-    } else if( gh_eq_p(type,gh_symbol2scm("user4")) ) {
-	i=User4Font;
-    } else if( gh_eq_p(type,gh_symbol2scm("user5")) ) {
-	i=User5Font;
-    } else {
-	fprintf(stderr,"unsupported font type\n");
-	return SCM_UNSPECIFIED;
-    }
-
+    i = CclFontByIdentifier(type);
     free(Fonts[i].File);
-    Fonts[i].File=gh_scm2newstr(file,NULL);
-    Fonts[i].Width=gh_scm2int(width);
-    Fonts[i].Height=gh_scm2int(height);
+    VideoSaveFree(Fonts[i].Graphic);
+    Fonts[i].Graphic=NULL;
+    Fonts[i].File = gh_scm2newstr(file, NULL);
+    Fonts[i].Width = gh_scm2int(width);
+    Fonts[i].Height = gh_scm2int(height);
 
     return SCM_UNSPECIFIED;
 }
@@ -767,16 +782,16 @@ local SCM CclDefineFontColors(SCM list)
     SCM value;
     SCM temp;
 
-    for( i=0; i<16; ++i ) {
-	value=gh_car(list);
-	list=gh_cdr(list);
+    for (i = 0; i < 16; ++i) {
+	value = gh_car(list);
+	list = gh_cdr(list);
 
-	if( gh_vector_length(value)!=7 ) {
-	    fprintf(stderr,"Wrong vector length\n");
+	if (gh_vector_length(value) != 7) {
+	    fprintf(stderr, "Wrong vector length\n");
 	}
-	for( j=0; j<7; ++j ) {
-	    temp=gh_vector_ref(value,gh_int2scm(j));
-	    FontColors[i][j]=gh_scm2int(temp);
+	for (j = 0; j < 7; ++j) {
+	    temp = gh_vector_ref(value, gh_int2scm(j));
+	    FontColors[i][j] = gh_scm2int(temp);
 	}
     }
 
@@ -812,7 +827,7 @@ global void CleanFonts(void)
 
     for( i=0; i<sizeof(Fonts)/sizeof(*Fonts); ++i ) {
 	free(Fonts[i].File);
-	VideoFree(Fonts[i].Graphic);
+	VideoSaveFree(Fonts[i].Graphic);
 	Fonts[i].File=NULL;
 	Fonts[i].Graphic=NULL;
     }