Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6507: Don't try to load invalid depots from older savegames #7546

Merged
merged 4 commits into from Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/saveload/afterload.cpp
Expand Up @@ -1900,6 +1900,7 @@ bool AfterLoadGame()
}

if (IsSavegameVersionBefore(SLV_62)) {
GroupStatistics::UpdateAfterLoad(); // Ensure statistics pool is initialised before trying to delete vehicles
/* Remove all trams from savegames without tram support.
* There would be trams without tram track under causing crashes sooner or later. */
RoadVehicle *v;
Expand Down Expand Up @@ -2311,6 +2312,14 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_128)) {
const Depot *d;
FOR_ALL_DEPOTS(d) {
/* At some point, invalid depots were saved into the game (possibly those removed in the past?)
* Remove them here, so they don't cause issues further down the line */
if (!IsDepotTile(d->xy)) {
DEBUG(sl, 0, "Removing invalid depot %d at %d, %d", d->index, TileX(d->xy), TileY(d->xy));
delete d;
d = nullptr;
PeterN marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
_m[d->xy].m2 = d->index;
if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
}
Expand Down
33 changes: 0 additions & 33 deletions src/saveload/saveload.cpp
Expand Up @@ -2887,36 +2887,3 @@ void FileToSaveLoad::SetTitle(const char *title)
{
strecpy(this->title, title, lastof(this->title));
}

#if 0
/**
* Function to get the type of the savegame by looking at the file header.
* NOTICE: Not used right now, but could be used if extensions of savegames are garbled
* @param file Savegame to be checked
* @return SL_OLD_LOAD or SL_LOAD of the file
*/
int GetSavegameType(char *file)
{
const SaveLoadFormat *fmt;
uint32 hdr;
FILE *f;
int mode = SL_OLD_LOAD;

f = fopen(file, "rb");
if (fread(&hdr, sizeof(hdr), 1, f) != 1) {
DEBUG(sl, 0, "Savegame is obsolete or invalid format");
mode = SL_LOAD; // don't try to get filename, just show name as it is written
} else {
/* see if we have any loader for this type. */
for (fmt = _saveload_formats; fmt != endof(_saveload_formats); fmt++) {
if (fmt->tag == hdr) {
mode = SL_LOAD; // new type of savegame
break;
}
}
}

fclose(f);
return mode;
}
#endif