mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-06 22:37:22 +00:00
(svn r8171) -Fix (FS#556): return SL_ERROR when unthreaded saves failed, to make sure we do not try to send zero-byte savegames.
This commit is contained in:
parent
1f3ea708c3
commit
0bd6622c2e
@ -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);
|
||||
|
@ -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);
|
||||
SaveFileDone();
|
||||
}
|
||||
(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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user