summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2006-11-22 14:14:02 +0000
committerrubidium <rubidium@openttd.org>2006-11-22 14:14:02 +0000
commit204d64b23888732693f545c4539d90b8fd1fc6dc (patch)
treed4299b13a2cc853b6b7727f8018c72cebcced034
parent77c564bd862d9e3a26d4fd4d82c3ab754b0e598d (diff)
downloadopenttd-204d64b23888732693f545c4539d90b8fd1fc6dc.tar.xz
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
-rw-r--r--genworld.c13
-rw-r--r--genworld.h3
-rw-r--r--tgp.c3
3 files changed, 19 insertions, 0 deletions
diff --git a/genworld.c b/genworld.c
index 55f7bb590..2e1f003d5 100644
--- a/genworld.c
+++ b/genworld.c
@@ -165,6 +165,15 @@ void GenerateWorldSetCallback(gw_done_proc *proc)
}
/**
+ * Set here the function, if any, that you want to be called when landscape
+ * generation is aborted.
+ */
+void GenerateWorldSetAbortCallback(gw_abort_proc *proc)
+{
+ _gw.abortp = proc;
+}
+
+/**
* This will wait for the thread to finish up his work. It will not continue
* till the work is done.
*/
@@ -201,12 +210,15 @@ void HandleGeneratingWorldAbortion(void)
/* Clean up - in SE create an empty map, otherwise, go to intro menu */
_switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU;
+ if (_gw.abortp != NULL) _gw.abortp();
+
if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE);
/* Show all vital windows again, because we have hidden them */
if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
_gw.active = false;
_gw.thread = NULL;
_gw.proc = NULL;
+ _gw.abortp = NULL;
_gw.threaded = false;
DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
@@ -229,6 +241,7 @@ void GenerateWorld(int mode, uint size_x, uint size_y)
_gw.size_y = size_y;
_gw.active = true;
_gw.abort = false;
+ _gw.abortp = NULL;
_gw.lp = _local_player;
_gw.wait_for_draw = false;
_gw.quit_thread = false;
diff --git a/genworld.h b/genworld.h
index bb882b1c1..0cf67cbe6 100644
--- a/genworld.h
+++ b/genworld.h
@@ -25,6 +25,7 @@ enum {
};
typedef void gw_done_proc(void);
+typedef void gw_abort_proc(void);
typedef struct gw_info {
bool active; //! Is generating world active
@@ -37,6 +38,7 @@ typedef struct gw_info {
uint size_x; //! X-size of the map
uint size_y; //! Y-size of the map
gw_done_proc *proc; //! Proc that is called when done (can be NULL)
+ gw_abort_proc *abortp; //! Proc that is called when aborting (can be NULL)
OTTDThread *thread; //! The thread we are in (can be NULL)
} gw_info;
@@ -74,6 +76,7 @@ void SetGeneratingWorldPaintStatus(bool status);
bool IsGeneratingWorldReadyForPaint(void);
bool IsGenerateWorldThreaded(void);
void GenerateWorldSetCallback(gw_done_proc *proc);
+void GenerateWorldSetAbortCallback(gw_abort_proc *proc);
void WaitTillGeneratedWorld(void);
void GenerateWorld(int mode, uint size_x, uint size_y);
void AbortGeneratingWorld(void);
diff --git a/tgp.c b/tgp.c
index 8c99856f6..d7f9722f9 100644
--- a/tgp.c
+++ b/tgp.c
@@ -798,6 +798,8 @@ void GenerateTerrainPerlin(void)
uint x, y;
if (!AllocHeightMap()) return;
+ GenerateWorldSetAbortCallback(FreeHeightMap);
+
HeightMapGenerate();
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
@@ -823,4 +825,5 @@ void GenerateTerrainPerlin(void)
for (x = 0; x < _height_map.size_x; x++) MakeVoid(_height_map.size_x * y + x);
FreeHeightMap();
+ GenerateWorldSetAbortCallback(NULL);
}