(svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
authorpeter1138
Wed, 03 May 2006 21:07:44 +0000
changeset 3740 4742b3d6f37b
parent 3739 c96a784d5c53
child 3741 92c022b64b28
(svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
newgrf.c
newgrf_station.h
--- a/newgrf.c	Wed May 03 20:51:42 2006 +0000
+++ b/newgrf.c	Wed May 03 21:07:44 2006 +0000
@@ -805,6 +805,8 @@
 
 				statspec->tiles = grf_load_extended(&buf);
 				statspec->renderdata = calloc(statspec->tiles, sizeof(*statspec->renderdata));
+				statspec->copied_renderdata = false;
+
 				for (t = 0; t < statspec->tiles; t++) {
 					DrawTileSprites *dts = &statspec->renderdata[t];
 					uint seq_count = 0;
@@ -850,6 +852,7 @@
 
 				statspec->tiles = srcstatspec->tiles;
 				statspec->renderdata = srcstatspec->renderdata;
+				statspec->copied_renderdata = true;
 			}
 			break;
 
@@ -2475,14 +2478,25 @@
 
 static void ResetCustomStations(void)
 {
+	StationSpec *statspec;
 	GRFFile *file;
 	uint i;
+	uint t;
 
 	for (file = _first_grffile; file != NULL; file = file->next) {
 		for (i = 0; i < file->num_stations; i++) {
 			if (file->stations[i].grfid != file->grfid) continue;
-
-			// TODO: Release renderdata, platforms and layouts
+			statspec = &file->stations[i];
+
+			/* Release renderdata, if it wasn't copied from another custom station spec  */
+			if (!statspec->copied_renderdata) {
+				for (t = 0; t < statspec->tiles; t++) {
+					free((void*)statspec->renderdata[t].seq);
+				}
+				free(statspec->renderdata);
+			}
+
+			// TODO: Release platforms and layouts
 		}
 
 		/* Free and reset the station data */
--- a/newgrf_station.h	Wed May 03 20:51:42 2006 +0000
+++ b/newgrf_station.h	Wed May 03 21:07:44 2006 +0000
@@ -44,6 +44,7 @@
 	 */
 	uint tiles;
 	DrawTileSprites *renderdata; ///< Array of tile layouts.
+	bool copied_renderdata;
 
 	/** Cargo threshold for choosing between little and lots of cargo
 	 * @note little/lots are equivalent to the moving/loading states for vehicles