From: fgsfds Date: Wed, 7 Aug 2019 21:43:23 +0000 (+0300) Subject: Game: Handle load errors correctly X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=6a8baf759e33dfda3cf8d9062b6989cfd090a695;p=d2df-sdl.git Game: Handle load errors correctly --- diff --git a/src/game/g_saveload.pas b/src/game/g_saveload.pas index 194b833..17a1866 100644 --- a/src/game/g_saveload.pas +++ b/src/game/g_saveload.pas @@ -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; diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 2117227..e62cc1c 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -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;