summaryrefslogtreecommitdiff
path: root/src/genworld_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-05-03 15:44:05 +0000
committerrubidium <rubidium@openttd.org>2009-05-03 15:44:05 +0000
commitd685ca0619cdbaf61623b673d26a2c9aa8b5b85e (patch)
treefa050ce2c3ba55aadcc588d3e60293e710e6b886 /src/genworld_gui.cpp
parentc29f4fd738f65678356718b8487cf18e196a2dec (diff)
downloadopenttd-d685ca0619cdbaf61623b673d26a2c9aa8b5b85e.tar.xz
(svn r16220) -Fix [FS#2862]: possible crashes when quiting OpenTTD or forcing resizes/redraws of the screen during map generation
Diffstat (limited to 'src/genworld_gui.cpp')
-rw-r--r--src/genworld_gui.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp
index f9c6082f8..dd5993892 100644
--- a/src/genworld_gui.cpp
+++ b/src/genworld_gui.cpp
@@ -26,6 +26,7 @@
#include "landscape_type.h"
#include "querystring_gui.h"
#include "town.h"
+#include "thread.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -1352,8 +1353,8 @@ static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total
_tp.percent = percent_table[cls];
}
- /* Don't update the screen too often. So update it once in every 200ms */
- if (!_network_dedicated && _tp.timer != 0 && _realtime_tick - _tp.timer < 200) return;
+ /* Don't update the screen too often. So update it once in every once in a while... */
+ if (!_network_dedicated && _tp.timer != 0 && _realtime_tick - _tp.timer < GENWORLD_REDRAW_TIMEOUT) return;
/* Percentage is about the number of completed tasks, so 'current - 1' */
_tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
@@ -1379,12 +1380,15 @@ static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total
InvalidateWindow(WC_GENERATE_PROGRESS_WINDOW, 0);
MarkWholeScreenDirty();
- SetGeneratingWorldPaintStatus(true);
- /* We wait here till the paint is done, so we don't read and write
- * on the same tile at the same moment. Nasty hack, but that happens
- * if you implement threading afterwards */
- while (IsGeneratingWorldReadyForPaint()) { CSleep(10); }
+ /* Release the rights to the map generator, and acquire the rights to the
+ * paint thread. The 'other' thread already has the paint thread rights so
+ * this ensures us that we are waiting until the paint thread is done
+ * before we reacquire the mapgen rights */
+ _genworld_mapgen_mutex->EndCritical();
+ _genworld_paint_mutex->BeginCritical();
+ _genworld_mapgen_mutex->BeginCritical();
+ _genworld_paint_mutex->EndCritical();
_tp.timer = _realtime_tick;
}