DEADSOFTWARE

Game: Handle load errors correctly
authorfgsfds <pvt.fgsfds@gmail.com>
Wed, 7 Aug 2019 21:43:23 +0000 (00:43 +0300)
committerfgsfds <pvt.fgsfds@gmail.com>
Wed, 7 Aug 2019 21:43:29 +0000 (00:43 +0300)
src/game/g_saveload.pas
src/shared/utils.pas

index 194b8337a06813310aacb4a7b39a808fbdc8da02..17a186698a26ed0c5cccb2ce8d4f336c4bbb1fd2 100644 (file)
@@ -501,14 +501,26 @@ begin
       st.Free();
     end;
   except
+    on e: EFileNotFoundException do
+      begin
+        g_Console_Add(_lc[I_GAME_ERROR_LOAD]);
+        g_Console_Add('LoadState Error: '+e.message);
+        e_WriteLog('LoadState Error: '+e.message, TMsgType.Warning);
+        gLoadGameMode := false;
+        result := false;
+      end;
     on e: Exception do
       begin
         g_Console_Add(_lc[I_GAME_ERROR_LOAD]);
+        g_Console_Add('LoadState Error: '+e.message);
         e_WriteLog('LoadState Error: '+e.message, TMsgType.Warning);
         {$IF DEFINED(D2F_DEBUG)}e_LogWritefln('stream error position: 0x%08x', [errpos], TMsgType.Warning);{$ENDIF}
         gLoadGameMode := false;
         result := false;
-        if not gameCleared then g_Game_Free();
+        if gState <> STATE_MENU then
+          g_FatalError(_lc[I_GAME_ERROR_LOAD])
+        else if not gameCleared then
+          g_Game_Free();
         {$IF DEFINED(D2F_DEBUG)}e_WriteStackTrace(e.message);{$ENDIF}
       end;
   end;
index 21172272a8a01ca64132494ddeed01fb63b0d27c..e62cc1c3fccd98571e3e6680a0216e093c452e86 100644 (file)
@@ -1159,7 +1159,7 @@ end;
 
 function openDiskFileRO (pathname: AnsiString): TStream;
 begin
-  if not findFileCI(pathname) then raise Exception.Create('can''t open file "'+pathname+'"');
+  if not findFileCI(pathname) then raise EFileNotFoundException.Create('can''t open file "'+pathname+'"');
   result := TFileStream.Create(pathname, fmOpenRead or {fmShareDenyWrite}fmShareDenyNone);
 end;