foxygit / doom Log in
commit 0b50fbde6a49250d4372a3255b1e1fd451326abe
Author:     Mike Swanson <mikeonthecomputer@gmail.com>
AuthorDate: Wed Feb 14 20:58:27 2018 -0800
Commit:     Mike Swanson <mikeonthecomputer@gmail.com>
CommitDate: Wed Feb 14 20:58:27 2018 -0800

    Print a more useful error about which savegame failed to load

    Amends the prior commit, also fixes the formatting for the I_Error()
    function call to represent the preferred format outlined in HACKING.

    Hexen now has two locations that can fail out with an error.  One in
    CopySaveSlot that should fail when a hex?.hxs file does not exist, as
    specified via the -loadgame parameter.  A second in the SV_OpenRead
    function that should probably never get triggered after the first; it
    would mean the hex6.hxs file wasn't created or somehow deleted in the
    middle of the function.  (Chocolate Hexen race condition exploits,
    anyone?)
---
 src/doom/g_game.c     | 2 +-
 src/heretic/p_saveg.c | 2 +-
 src/hexen/sv_save.c   | 7 ++++++-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/doom/g_game.c b/src/doom/g_game.c
index 89aaafed..a5347edf 100644
--- a/src/doom/g_game.c
+++ b/src/doom/g_game.c
@@ -1553,7 +1553,7 @@ void G_DoLoadGame (void)

     if (save_stream == NULL)
     {
-        I_Error ("Could not load savegame");
+        I_Error("Could not load savegame %s", savename);
     }

     savegame_error = false;
diff --git a/src/heretic/p_saveg.c b/src/heretic/p_saveg.c
index 0439f295..75b9c573 100644
--- a/src/heretic/p_saveg.c
+++ b/src/heretic/p_saveg.c
@@ -69,7 +69,7 @@ void SV_OpenRead(char *filename)

     if (SaveGameFP == NULL)
     {
-        I_Error ("Could not load savegame");
+        I_Error("Could not load savegame %s", filename);
     }
 }

diff --git a/src/hexen/sv_save.c b/src/hexen/sv_save.c
index 02b43694..bd8f1f98 100644
--- a/src/hexen/sv_save.c
+++ b/src/hexen/sv_save.c
@@ -3238,6 +3238,10 @@ static void CopySaveSlot(int sourceSlot, int destSlot)
                    "%shex%d.hxs", SavePath, destSlot);
         CopyFile(sourceName, destName);
     }
+    else
+    {
+        I_Error("Could not load savegame %s", sourceName);
+    }
 }

 //==========================================================================
@@ -3344,9 +3348,10 @@ static void SV_OpenRead(char *fileName)
 {
     SavingFP = fopen(fileName, "rb");

+    // Should never happen, only if hex6.hxs cannot ever be created.
     if (SavingFP == NULL)
     {
-        I_Error ("Could not load savegame");
+        I_Error("Could not load savegame %s", fileName);
     }
 }