Copy string from SDL_JoystickNameForIndex before the subsystem is shut down
This commit is contained in:
parent
0f11116e7b
commit
19d19543b7
|
@ -1455,16 +1455,34 @@ INT32 I_NumJoys(void)
|
||||||
|
|
||||||
const char *I_GetJoyName(INT32 joyindex)
|
const char *I_GetJoyName(INT32 joyindex)
|
||||||
{
|
{
|
||||||
const char *joyname = "NA";
|
const char *tempname = NULL;
|
||||||
|
size_t templen;
|
||||||
|
char *joyname = NULL;
|
||||||
joyindex--; //SDL's Joystick System starts at 0, not 1
|
joyindex--; //SDL's Joystick System starts at 0, not 1
|
||||||
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
|
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
|
||||||
{
|
{
|
||||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1)
|
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1)
|
||||||
joyname = SDL_JoystickNameForIndex(joyindex);
|
{
|
||||||
|
tempname = SDL_JoystickNameForIndex(joyindex);
|
||||||
|
if (tempname)
|
||||||
|
{
|
||||||
|
templen = strlen(tempname);
|
||||||
|
joyname = malloc(templen*sizeof(char));
|
||||||
|
strcpy(joyname, tempname);
|
||||||
|
}
|
||||||
|
}
|
||||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
joyname = SDL_JoystickNameForIndex(joyindex);
|
{
|
||||||
|
tempname = SDL_JoystickNameForIndex(joyindex);
|
||||||
|
if (tempname)
|
||||||
|
{
|
||||||
|
templen = strlen(tempname);
|
||||||
|
joyname = malloc(templen*sizeof(char));
|
||||||
|
strcpy(joyname, tempname);
|
||||||
|
}
|
||||||
|
}
|
||||||
return joyname;
|
return joyname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1577,16 +1577,34 @@ INT32 I_NumJoys(void)
|
||||||
|
|
||||||
const char *I_GetJoyName(INT32 joyindex)
|
const char *I_GetJoyName(INT32 joyindex)
|
||||||
{
|
{
|
||||||
const char *joyname = "NA";
|
const char *tempname = NULL;
|
||||||
|
size_t templen;
|
||||||
|
char *joyname = NULL;
|
||||||
joyindex--; //SDL's Joystick System starts at 0, not 1
|
joyindex--; //SDL's Joystick System starts at 0, not 1
|
||||||
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
|
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
|
||||||
{
|
{
|
||||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1)
|
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1)
|
||||||
joyname = SDL_JoystickName(joyindex);
|
{
|
||||||
|
tempname = SDL_JoystickNameForIndex(joyindex);
|
||||||
|
if (tempname)
|
||||||
|
{
|
||||||
|
templen = strlen(tempname);
|
||||||
|
joyname = malloc(templen*sizeof(char));
|
||||||
|
strcpy(joyname, tempname);
|
||||||
|
}
|
||||||
|
}
|
||||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
joyname = SDL_JoystickName(joyindex);
|
{
|
||||||
|
tempname = SDL_JoystickNameForIndex(joyindex);
|
||||||
|
if (tempname)
|
||||||
|
{
|
||||||
|
templen = strlen(tempname);
|
||||||
|
joyname = malloc(templen*sizeof(char));
|
||||||
|
strcpy(joyname, tempname);
|
||||||
|
}
|
||||||
|
}
|
||||||
return joyname;
|
return joyname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue