summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-01-17 00:01:55 +0000
committerrubidium <rubidium@openttd.org>2007-01-17 00:01:55 +0000
commit3ce83d41fa35a8c3977864d9de256b73b04f2844 (patch)
treef18e7e3b826abdeb6455e527372367cad4d8b237
parent4b3cbf1a14d0ffd43839428cbe38a90ad192dde8 (diff)
downloadopenttd-3ce83d41fa35a8c3977864d9de256b73b04f2844.tar.xz
(svn r8171) -Fix (FS#556): return SL_ERROR when unthreaded saves failed, to make sure we do not try to send zero-byte savegames.
-rw-r--r--src/network/network_server.cpp2
-rw-r--r--src/saveload.cpp25
2 files changed, 19 insertions, 8 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 202220f34..612a9edef 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -289,6 +289,8 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
file_pointer = fopen(filename, "rb");
fseek(file_pointer, 0, SEEK_END);
+ if (ftell(file_pointer) == 0) error("network savedump failed - zero sized savegame?");
+
// Now send the _frame_counter and how many packets are coming
p = NetworkSend_Init(PACKET_SERVER_MAP);
NetworkSend_uint8(p, MAP_PACKET_START);
diff --git a/src/saveload.cpp b/src/saveload.cpp
index 65e6e454d..ee4a99187 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -1428,7 +1428,7 @@ static OTTDThread* save_thread;
/** We have written the whole game into memory, _Savegame_pool, now find
* and appropiate compressor and start writing to file.
*/
-static void* SaveFileToDisk(void *arg)
+static SaveOrLoadResult SaveFileToDisk(bool threaded)
{
const SaveLoadFormat *fmt;
uint32 hdr[2];
@@ -1440,12 +1440,12 @@ static void* SaveFileToDisk(void *arg)
_sl.excpt_uninit();
fprintf(stderr, "Save game failed: %s.", _sl.excpt_msg);
- if (arg != NULL) {
+ if (threaded) {
OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_ERROR);
} else {
SaveFileError();
}
- return NULL;
+ return SL_ERROR;
}
fmt = GetSavegameFormat(_savegame_format);
@@ -1478,7 +1478,14 @@ static void* SaveFileToDisk(void *arg)
GetSavegameFormat("memory")->uninit_write(); // clean the memorypool
fclose(_sl.fh);
- if (arg != NULL) OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_DONE);
+ if (threaded) OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_DONE);
+
+ return SL_OK;
+}
+
+static void* SaveFileToDiskThread(void *arg)
+{
+ SaveFileToDisk(true);
return NULL;
}
@@ -1567,12 +1574,14 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
SaveFileStart();
if (_network_server ||
- (save_thread = OTTDCreateThread(&SaveFileToDisk, (void*)"")) == NULL) {
- DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
- SaveFileToDisk(NULL);
+ (save_thread = OTTDCreateThread(&SaveFileToDiskThread, NULL)) == NULL) {
+ if (!_network_server) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
+
+ SaveOrLoadResult result = SaveFileToDisk(false);
SaveFileDone();
- }
+ return result;
+ }
} else { /* LOAD game */
assert(mode == SL_LOAD);