Skip to content

Commit

Permalink
Fixed save/load crash (hack) on threaded build
Browse files Browse the repository at this point in the history
  • Loading branch information
angguss committed Aug 24, 2017
1 parent 980315c commit 4ccfeb8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/saveload/saveload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,9 @@ struct MemoryDumper {

while (t > 0) {
size_t to_write = min(MEMORY_CHUNK_SIZE, t);

writer->Write(this->blocks[i++], to_write);
t -= to_write;
}

writer->Finish();
}

Expand Down Expand Up @@ -2480,7 +2478,6 @@ static void SaveFileDone()
{
if (_game_mode != GM_MENU) _fast_forward = _sl.ff_state;
SetMouseCursorBusy(false);

InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH);
_sl.saveinprogress = false;
}
Expand Down Expand Up @@ -2593,14 +2590,20 @@ static SaveOrLoadResult DoSave(SaveFilter *writer, bool threaded)
SlSaveChunks();

SaveFileStart();
// File writes inside a pthread seem to crash on flush on the Vita,
// no clue why but this stops it crashing not lzma-specific though.
// hacky fix but it works for now
#if !defined(PSVITA)
if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread, "ottd:savegame")) {
if (threaded) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");

#endif
SaveOrLoadResult result = SaveFileToDisk(false);
SaveFileDone();

return result;
#if !defined(PSVITA)
}
#endif

return SL_OK;
}
Expand Down

0 comments on commit 4ccfeb8

Please sign in to comment.