DEADSOFTWARE

sdl1/2: fix invalid window title
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 13 Jul 2022 14:20:06 +0000 (17:20 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 13 Jul 2022 14:20:06 +0000 (17:20 +0300)
src/game/sdl/g_system.pas
src/game/sdl2/g_system.pas

index 1f4061abf7fdc4ba9ff74475e09d7ece908356e1..0df28dc724dc5b391f37dc85b7a8373a12070727 100644 (file)
@@ -124,17 +124,17 @@ implementation
     g_Game_ClearLoading;
   end;
 
     g_Game_ClearLoading;
   end;
 
-  function GetTitle (): PChar;
+  function GetTitle (): AnsiString;
     var info: AnsiString;
   begin
     info := g_GetBuildHash(false);
     if info = 'custom build' then
       info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME;
     var info: AnsiString;
   begin
     info := g_GetBuildHash(false);
     if info = 'custom build' then
       info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME;
-    result := PChar(Format(GameTitle, [info]))
+    result := Format(GameTitle, [info]);
   end;
 
   function InitWindow (w, h, bpp: Integer; fullScreen: Boolean): Boolean;
   end;
 
   function InitWindow (w, h, bpp: Integer; fullScreen: Boolean): Boolean;
-    var flags: Uint32;
+    var flags: Uint32; title: AnsiString;
   begin
     e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]);
     result := false;
   begin
     e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]);
     result := false;
@@ -158,7 +158,8 @@ implementation
           e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal);
           exit;
         end;
           e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal);
           exit;
         end;
-        SDL_WM_SetCaption(GetTitle(), nil);
+        title := GetTitle();
+        SDL_WM_SetCaption(PChar(title), nil);
         gFullScreen := fullscreen;
         gRC_FullScreen := fullscreen;
         UpdateSize(w, h);
         gFullScreen := fullscreen;
         gRC_FullScreen := fullscreen;
         UpdateSize(w, h);
@@ -184,7 +185,7 @@ implementation
   function sys_GetDisplayModes (bpp: Integer): SSArray;
     var m: PPSDL_Rect; f: TSDL_PixelFormat; i, count: Integer;
   begin
   function sys_GetDisplayModes (bpp: Integer): SSArray;
     var m: PPSDL_Rect; f: TSDL_PixelFormat; i, count: Integer;
   begin
-    SetLength(result, 0);
+    result := nil;
     FillChar(f, sizeof(f), 0);
     f.palette := nil;
     f.BitsPerPixel := bpp;
     FillChar(f, sizeof(f), 0);
     f.palette := nil;
     f.BitsPerPixel := bpp;
index eec03232f7d26e99fd2619d39994ff5291b26257..9cd1ee194b0ae4b89bb587e593c689067fd477cb 100644 (file)
@@ -134,17 +134,17 @@ implementation
     {$ENDIF}
   end;
 
     {$ENDIF}
   end;
 
-  function GetTitle (): PChar;
+  function GetTitle (): AnsiString;
     var info: AnsiString;
   begin
     info := g_GetBuildHash(false);
     if info = 'custom build' then
       info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME;
     var info: AnsiString;
   begin
     info := g_GetBuildHash(false);
     if info = 'custom build' then
       info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME;
-    result := PChar(Format(GameTitle, [info]))
+    result := Format(GameTitle, [info]);
   end;
 
   function InitWindow (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean;
   end;
 
   function InitWindow (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean;
-    var flags: UInt32; x, y: cint;
+    var flags: UInt32; x, y: cint; title: AnsiString;
   begin
     // note: on window close make: if assigned(oglDeinitCB) then oglDeinitCB;
     e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]);
   begin
     // note: on window close make: if assigned(oglDeinitCB) then oglDeinitCB;
     e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]);
@@ -178,7 +178,8 @@ implementation
         x := wx;
         y := wy
       end;
         x := wx;
         y := wy
       end;
-      window := SDL_CreateWindow(GetTitle(), x, y, w, h, flags);
+      title := GetTitle();
+      window := SDL_CreateWindow(PChar(title), x, y, w, h, flags);
       if window <> nil then
       begin
         context := SDL_GL_CreateContext(window);
       if window <> nil then
       begin
         context := SDL_GL_CreateContext(window);