Prevent game crash on bad savegame title

It was noted in issues #1207 and #1232 that game can crash when savegame
does not contain title. This might be a problem when saving game fails
and user is informed about it only in console. Proper fix should be a
visible error message informing that saving failed. This commit filters
invalid savegames from load windows and prevents game crash in narrow
cases.
1164-fix
Krzysztof Dermont 2020-07-05 22:44:42 +02:00 committed by Mateusz Przybył
parent c04b2738de
commit a65776e0e7
2 changed files with 10 additions and 3 deletions

View File

@ -478,14 +478,21 @@ std::vector<SavedScene> CPlayerProfile::GetSavedSceneList()
for (auto dir : saveDirs)
{
std::string savegameFile = GetSaveFile(dir+"/data.sav");
if (CResourceManager::Exists(savegameFile))
if (CResourceManager::Exists(savegameFile) && CResourceManager::GetFileSize(savegameFile) > 0)
{
CLevelParser levelParser(savegameFile);
levelParser.Load();
CLevelParserLine* line = levelParser.GetIfDefined("Created");
int time = line != nullptr ? line->GetParam("date")->AsInt() : 0;
try
{
sortedSaveDirs[time] = SavedScene(GetSaveFile(dir), levelParser.Get("Title")->GetParam("text")->AsString());
}
catch (CLevelParserException &e)
{
GetLogger()->Error("Error trying to load savegame title: %s\n", e.what());
}
}
}
std::vector<SavedScene> result;

View File

@ -4738,7 +4738,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s
}
catch (CLevelParserException& e)
{
GetLogger()->Error("Failed to save level state - %s\n", e.what());
GetLogger()->Error("Failed to save level state - %s\n", e.what()); // TODO add visual error to notify user that save failed
return false;
}