mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
- use std::unique_ptr to manage the resource file for loading a savegame because the try/catch handler to ensure its deletion was causing some problems.
This commit is contained in:
parent
f9ef935840
commit
f15b051327
1 changed files with 135 additions and 153 deletions
|
@ -1891,18 +1891,15 @@ void G_DoLoadGame ()
|
||||||
hidecon = gameaction == ga_loadgamehidecon;
|
hidecon = gameaction == ga_loadgamehidecon;
|
||||||
gameaction = ga_nothing;
|
gameaction = ga_nothing;
|
||||||
|
|
||||||
FResourceFile *resfile = FResourceFile::OpenResourceFile(savename.GetChars(), nullptr, true, true);
|
std::unique_ptr<FResourceFile> resfile(FResourceFile::OpenResourceFile(savename.GetChars(), nullptr, true, true));
|
||||||
if (resfile == nullptr)
|
if (resfile == nullptr)
|
||||||
{
|
{
|
||||||
Printf ("Could not read savegame '%s'\n", savename.GetChars());
|
Printf ("Could not read savegame '%s'\n", savename.GetChars());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
FResourceLump *info = resfile->FindLump("info.json");
|
FResourceLump *info = resfile->FindLump("info.json");
|
||||||
if (info == nullptr)
|
if (info == nullptr)
|
||||||
{
|
{
|
||||||
delete resfile;
|
|
||||||
Printf("'%s' is not a valid savegame: Missing 'info.json'.\n", savename.GetChars());
|
Printf("'%s' is not a valid savegame: Missing 'info.json'.\n", savename.GetChars());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1914,7 +1911,6 @@ void G_DoLoadGame ()
|
||||||
if (!arc.OpenReader((const char *)data, info->LumpSize))
|
if (!arc.OpenReader((const char *)data, info->LumpSize))
|
||||||
{
|
{
|
||||||
Printf("Failed to access savegame info\n");
|
Printf("Failed to access savegame info\n");
|
||||||
delete resfile;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1938,13 +1934,11 @@ void G_DoLoadGame ()
|
||||||
{
|
{
|
||||||
Printf("Savegame is from another ZDoom-based engine: %s\n", engine.GetChars());
|
Printf("Savegame is from another ZDoom-based engine: %s\n", engine.GetChars());
|
||||||
}
|
}
|
||||||
delete resfile;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SaveVersion < MINSAVEVER || SaveVersion > SAVEVER)
|
if (SaveVersion < MINSAVEVER || SaveVersion > SAVEVER)
|
||||||
{
|
{
|
||||||
delete resfile;
|
|
||||||
Printf("Savegame is from an incompatible version");
|
Printf("Savegame is from an incompatible version");
|
||||||
if (SaveVersion < MINSAVEVER)
|
if (SaveVersion < MINSAVEVER)
|
||||||
{
|
{
|
||||||
|
@ -1960,14 +1954,12 @@ void G_DoLoadGame ()
|
||||||
|
|
||||||
if (!G_CheckSaveGameWads(arc, true))
|
if (!G_CheckSaveGameWads(arc, true))
|
||||||
{
|
{
|
||||||
delete resfile;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.IsEmpty())
|
if (map.IsEmpty())
|
||||||
{
|
{
|
||||||
Printf("Savegame is missing the current map\n");
|
Printf("Savegame is missing the current map\n");
|
||||||
delete resfile;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1983,7 +1975,6 @@ void G_DoLoadGame ()
|
||||||
info = resfile->FindLump("globals.json");
|
info = resfile->FindLump("globals.json");
|
||||||
if (info == nullptr)
|
if (info == nullptr)
|
||||||
{
|
{
|
||||||
delete resfile;
|
|
||||||
Printf("'%s' is not a valid savegame: Missing 'globals.json'.\n", savename.GetChars());
|
Printf("'%s' is not a valid savegame: Missing 'globals.json'.\n", savename.GetChars());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1992,7 +1983,6 @@ void G_DoLoadGame ()
|
||||||
if (!arc.OpenReader((const char *)data, info->LumpSize))
|
if (!arc.OpenReader((const char *)data, info->LumpSize))
|
||||||
{
|
{
|
||||||
Printf("Failed to access savegame info\n");
|
Printf("Failed to access savegame info\n");
|
||||||
delete resfile;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2017,9 +2007,8 @@ void G_DoLoadGame ()
|
||||||
// dearchive all the modifications
|
// dearchive all the modifications
|
||||||
level.time = Scale(time[1], TICRATE, time[0]);
|
level.time = Scale(time[1], TICRATE, time[0]);
|
||||||
|
|
||||||
G_ReadSnapshots(resfile);
|
G_ReadSnapshots(resfile.get());
|
||||||
delete resfile; // we no longer need the resource file below this point
|
resfile.reset(nullptr); // we no longer need the resource file below this point
|
||||||
resfile = nullptr;
|
|
||||||
G_ReadVisited(arc);
|
G_ReadVisited(arc);
|
||||||
|
|
||||||
// load a base level
|
// load a base level
|
||||||
|
@ -2047,13 +2036,6 @@ void G_DoLoadGame ()
|
||||||
// collection.
|
// collection.
|
||||||
GC::StartCollection();
|
GC::StartCollection();
|
||||||
}
|
}
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
// delete the resource file if anything goes wrong in here.
|
|
||||||
if (resfile != nullptr) delete resfile;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue