mirror of https://github.com/OpenTTD/OpenTTD
Fix #7925: Reset temporary saveload data at the start of loading a savegame instead of at the end.
Otherwise temporary data may be passed from an aborted load action to the next load action.pull/7934/head
parent
41163331aa
commit
a4be4514c9
|
@ -140,6 +140,11 @@ void CopyTempEngineData()
|
||||||
if (se->name != nullptr) e->name = stredup(se->name);
|
if (se->name != nullptr) e->name = stredup(se->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResetTempEngineData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetTempEngineData()
|
||||||
|
{
|
||||||
/* Get rid of temporary data */
|
/* Get rid of temporary data */
|
||||||
for (std::vector<Engine*>::iterator it = _temp_engine.begin(); it != _temp_engine.end(); ++it) {
|
for (std::vector<Engine*>::iterator it = _temp_engine.begin(); it != _temp_engine.end(); ++it) {
|
||||||
FreeEngine(*it);
|
FreeEngine(*it);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "../tunnelbridge_map.h"
|
#include "../tunnelbridge_map.h"
|
||||||
|
|
||||||
#include "saveload.h"
|
#include "saveload.h"
|
||||||
|
#include "saveload_internal.h"
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
|
||||||
|
@ -79,6 +80,11 @@ void AfterLoadLabelMaps()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResetLabelMaps();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetLabelMaps()
|
||||||
|
{
|
||||||
_railtype_list.clear();
|
_railtype_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +112,7 @@ static void Save_RAIL()
|
||||||
|
|
||||||
static void Load_RAIL()
|
static void Load_RAIL()
|
||||||
{
|
{
|
||||||
_railtype_list.clear();
|
ResetLabelMaps();
|
||||||
|
|
||||||
LabelObject lo;
|
LabelObject lo;
|
||||||
|
|
||||||
|
|
|
@ -2377,6 +2377,16 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
||||||
extern bool AfterLoadGame();
|
extern bool AfterLoadGame();
|
||||||
extern bool LoadOldSaveGame(const char *file);
|
extern bool LoadOldSaveGame(const char *file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear temporary data that is passed between various saveload phases.
|
||||||
|
*/
|
||||||
|
static void ResetSaveloadData()
|
||||||
|
{
|
||||||
|
ResetTempEngineData();
|
||||||
|
ResetLabelMaps();
|
||||||
|
ResetOldWaypoints();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear/free saveload state.
|
* Clear/free saveload state.
|
||||||
*/
|
*/
|
||||||
|
@ -2623,6 +2633,8 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
|
||||||
_next_offs = 0;
|
_next_offs = 0;
|
||||||
|
|
||||||
if (!load_check) {
|
if (!load_check) {
|
||||||
|
ResetSaveloadData();
|
||||||
|
|
||||||
/* Old maps were hardcoded to 256x256 and thus did not contain
|
/* Old maps were hardcoded to 256x256 and thus did not contain
|
||||||
* any mapsize information. Pre-initialize to 256x256 to not to
|
* any mapsize information. Pre-initialize to 256x256 to not to
|
||||||
* confuse old games */
|
* confuse old games */
|
||||||
|
@ -2727,6 +2739,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, SaveLoadOperation fop, Detaile
|
||||||
try {
|
try {
|
||||||
/* Load a TTDLX or TTDPatch game */
|
/* Load a TTDLX or TTDPatch game */
|
||||||
if (fop == SLO_LOAD && dft == DFT_OLD_GAME_FILE) {
|
if (fop == SLO_LOAD && dft == DFT_OLD_GAME_FILE) {
|
||||||
|
ResetSaveloadData();
|
||||||
|
|
||||||
InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
|
InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
|
||||||
|
|
||||||
/* TTD/TTO savegames have no NewGRFs, TTDP savegame have them
|
/* TTD/TTO savegames have no NewGRFs, TTDP savegame have them
|
||||||
|
|
|
@ -20,6 +20,7 @@ StringID RemapOldStringID(StringID s);
|
||||||
char *CopyFromOldName(StringID id);
|
char *CopyFromOldName(StringID id);
|
||||||
void ResetOldNames();
|
void ResetOldNames();
|
||||||
|
|
||||||
|
void ResetOldWaypoints();
|
||||||
void MoveBuoysToWaypoints();
|
void MoveBuoysToWaypoints();
|
||||||
void MoveWaypointsToBaseStations();
|
void MoveWaypointsToBaseStations();
|
||||||
const SaveLoad *GetBaseStationDescription();
|
const SaveLoad *GetBaseStationDescription();
|
||||||
|
@ -28,6 +29,7 @@ void AfterLoadVehicles(bool part_of_load);
|
||||||
void FixupTrainLengths();
|
void FixupTrainLengths();
|
||||||
void AfterLoadStations();
|
void AfterLoadStations();
|
||||||
void AfterLoadRoadStops();
|
void AfterLoadRoadStops();
|
||||||
|
void ResetLabelMaps();
|
||||||
void AfterLoadLabelMaps();
|
void AfterLoadLabelMaps();
|
||||||
void AfterLoadStoryBook();
|
void AfterLoadStoryBook();
|
||||||
void AfterLoadLinkGraphs();
|
void AfterLoadLinkGraphs();
|
||||||
|
@ -42,6 +44,7 @@ void ResetViewportAfterLoadGame();
|
||||||
void ConvertOldMultiheadToNew();
|
void ConvertOldMultiheadToNew();
|
||||||
void ConnectMultiheadedTrains();
|
void ConnectMultiheadedTrains();
|
||||||
|
|
||||||
|
void ResetTempEngineData();
|
||||||
Engine *GetTempDataEngine(EngineID index);
|
Engine *GetTempDataEngine(EngineID index);
|
||||||
void CopyTempEngineData();
|
void CopyTempEngineData();
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,11 @@ void MoveWaypointsToBaseStations()
|
||||||
UpdateWaypointOrder(&v->current_order);
|
UpdateWaypointOrder(&v->current_order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResetOldWaypoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetOldWaypoints()
|
||||||
|
{
|
||||||
_old_waypoints.clear();
|
_old_waypoints.clear();
|
||||||
_old_waypoints.shrink_to_fit();
|
_old_waypoints.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
@ -182,7 +187,7 @@ static const SaveLoad _old_waypoint_desc[] = {
|
||||||
static void Load_WAYP()
|
static void Load_WAYP()
|
||||||
{
|
{
|
||||||
/* Precaution for when loading failed and it didn't get cleared */
|
/* Precaution for when loading failed and it didn't get cleared */
|
||||||
_old_waypoints.clear();
|
ResetOldWaypoints();
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue