From 6de9a0ffb257944b1554df0925c30691f060a01a Mon Sep 17 00:00:00 2001
From: daniel <daniel@freepascal.org>
Date: Sun, 11 Jun 2006 10:11:34 +0000
Subject: [PATCH]   * Handle video initialization failure.

git-svn-id: trunk@3843 -
---
 fv/app.pas     | 16 ++++++++++++----
 fv/drivers.pas | 17 +++++++++++------
 fv/str.inc     |  1 +
 fv/strtxt.inc  |  3 ++-
 4 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/fv/app.pas b/fv/app.pas
index 44ffcc1640..e51b7f958e 100644
--- a/fv/app.pas
+++ b/fv/app.pas
@@ -971,16 +971,24 @@ END;
 {  Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB              }
 {---------------------------------------------------------------------------}
 CONSTRUCTOR TApplication.Init;
+
 BEGIN
 {   InitMemory;}                                              { Start memory up }
+   InitResource;
    initkeyboard;
-   Drivers.InitVideo;                                         { Start video up }
+   if not Drivers.InitVideo then                              { Start video up }
+     begin
+       donekeyboard;
+       {Initresource might have failed.}
+       if strings<>nil then
+         writeln(strings^.get(sVideoFailed));
+       halt(1);
+     end;
    Drivers.InitEvents;                                        { Start event drive }
    Drivers.InitSysError;                                      { Start system error }
    InitHistory;                                               { Start history up }
-   InitResource;
-   InitMsgBox;
    Inherited Init;                                            { Call ancestor }
+   InitMsgBox;
    { init mouse and cursor }
    Video.SetCursorType(crHidden);
    Mouse.SetMouseXY(1,1);
@@ -993,12 +1001,12 @@ DESTRUCTOR TApplication.Done;
 BEGIN
    Inherited Done;                                    { Call ancestor }
    DoneHistory;                                       { Close history }
-   DoneResource;
    Drivers.DoneSysError;                                      { Close system error }
    Drivers.DoneEvents;                                        { Close event drive }
    drivers.donevideo;
 {   DoneMemory;}                                       { Close memory }
    donekeyboard;
+   DoneResource;
 END;
 
 {--TApplication-------------------------------------------------------------}
diff --git a/fv/drivers.pas b/fv/drivers.pas
index 6f95dcadbe..a3426e6f0b 100644
--- a/fv/drivers.pas
+++ b/fv/drivers.pas
@@ -488,7 +488,7 @@ Initializes the video manager, Saves the current screen mode in
 StartupMode, and switches to the mode indicated by ScreenMode.
 19May98 LdB
 ---------------------------------------------------------------------}
-PROCEDURE InitVideo;
+function InitVideo:boolean;
 
 {-DoneVideo---------------------------------------------------------
 Terminates the video manager by restoring the initial screen mode
@@ -1304,10 +1304,12 @@ end;
 {---------------------------------------------------------------------------}
 {  InitVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 26Nov99 LdB         }
 {---------------------------------------------------------------------------}
-PROCEDURE InitVideo;
-VAR
-  StoreScreenMode : TVideoMode;
-BEGIN
+function InitVideo:boolean;
+
+var StoreScreenMode : TVideoMode;
+
+begin
+  initvideo:=false;
   if VideoInitialized then
     begin
       StoreScreenMode:=ScreenMode;
@@ -1317,6 +1319,8 @@ BEGIN
     StoreScreenMode.Col:=0;
 
   Video.InitVideo;
+  if video.errorcode<>viook then
+    exit;
   GetVideoMode(StartupScreenMode);
   GetVideoMode(ScreenMode);
 {$ifdef win32}
@@ -1338,7 +1342,8 @@ BEGIN
   ScreenWidth:=Video.ScreenWidth;
   ScreenHeight:=Video.ScreenHeight;
   VideoInitialized:=true;
-END;
+  initvideo:=true;
+end;
 
 {---------------------------------------------------------------------------}
 {  DoneVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB         }
diff --git a/fv/str.inc b/fv/str.inc
index 6bf78f42eb..c833c69155 100644
--- a/fv/str.inc
+++ b/fv/str.inc
@@ -1,4 +1,5 @@
 { Strings }
+sVideoFailed = 0; {Video initialization failed.}
 sButtonDefault = 1; { Button default }
 sButtonDisabled = 2; { Button disabled }
 sButtonNormal = 3; { Button normal }
diff --git a/fv/strtxt.inc b/fv/strtxt.inc
index 1093abcbe6..361b1b98b7 100644
--- a/fv/strtxt.inc
+++ b/fv/strtxt.inc
@@ -3,8 +3,9 @@ type standard_string=record
        text:Pchar;
      end;
 
-const standard_string_count=106;
+const standard_string_count=107;
       standard_strings:array[0..standard_string_count-1] of standard_string=(
+          (nr:sVideoFailed;text:'Video initialization failed.'),
           (nr:sButtonDefault;text:'Button default'),
           (nr:sButtonDisabled;text:'Button disabled'),
           (nr:sButtonNormal;text:'Button normal'),