Fix hwengine crash when using >1 controllers 0.9.24
authorWuzzy <Wuzzy2@mail.ru>
Mon, 16 Jul 2018 20:28:01 +0200
branch0.9.24
changeset 13547 214dde864805
parent 13546 46ee00a7526a
child 13548 19d290017b69
Fix hwengine crash when using >1 controllers Reason: Data type mismatch for SDL_JoystickName, we wed in an index, but it expected a controller handle. Solution: Switch to SDL_JoystickNameForIndex.
hedgewars/SDLh.pas
hedgewars/uInputHandler.pas
--- a/hedgewars/SDLh.pas	Tue Jul 24 18:37:52 2018 +0200
+++ b/hedgewars/SDLh.pas	Mon Jul 16 20:28:01 2018 +0200
@@ -1167,7 +1167,7 @@
 procedure SDL_UnlockAudio; cdecl; external SDLLibName;
 
 function  SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
-function  SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName;
+function  SDL_JoystickNameForIndex(idx: LongInt): PChar; cdecl; external SDLLibName;
 function  SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName;
 function  SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName;
 function  SDL_JoystickIndex(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
--- a/hedgewars/uInputHandler.pas	Tue Jul 24 18:37:52 2018 +0200
+++ b/hedgewars/uInputHandler.pas	Mon Jul 16 20:28:01 2018 +0200
@@ -542,10 +542,10 @@
     begin
     for j:= 0 to pred(ControllerNumControllers) do
         begin
-        WriteLnToConsole('Using game controller: ' + shortstring(SDL_JoystickName(j)));
+        WriteLnToConsole('Game controller no. ' + IntToStr(j) + ', name "' + shortstring(SDL_JoystickNameForIndex(j)) + '":');
         Controller[j]:= SDL_JoystickOpen(j);
         if Controller[j] = nil then
-            WriteLnToConsole('* Failed to open game controller!')
+            WriteLnToConsole('* Failed to open game controller no. ' + IntToStr(j) + '!')
         else
             begin
             ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]);