summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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);