Fix bug 545, by returning early whenever an error occurs when initializing joystick structure
--HG-- branch : SDL-1.2 extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402925
This commit is contained in:
parent
7bc2820de9
commit
a4948e3c6c
1 changed files with 59 additions and 56 deletions
|
@ -112,13 +112,17 @@ SDL_Joystick *SDL_JoystickOpen(int device_index)
|
|||
|
||||
/* Create and initialize the joystick */
|
||||
joystick = (SDL_Joystick *)SDL_malloc((sizeof *joystick));
|
||||
if ( joystick != NULL ) {
|
||||
if ( !joystick ) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
SDL_memset(joystick, 0, (sizeof *joystick));
|
||||
joystick->index = device_index;
|
||||
if ( SDL_SYS_JoystickOpen(joystick) < 0 ) {
|
||||
SDL_free(joystick);
|
||||
joystick = NULL;
|
||||
} else {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if ( joystick->naxes > 0 ) {
|
||||
joystick->axes = (Sint16 *)SDL_malloc
|
||||
(joystick->naxes*sizeof(Sint16));
|
||||
|
@ -141,8 +145,9 @@ SDL_Joystick *SDL_JoystickOpen(int device_index)
|
|||
|| ((joystick->nbuttons > 0) && !joystick->buttons)) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_JoystickClose(joystick);
|
||||
joystick = NULL;
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if ( joystick->axes ) {
|
||||
SDL_memset(joystick->axes, 0,
|
||||
joystick->naxes*sizeof(Sint16));
|
||||
|
@ -159,9 +164,7 @@ SDL_Joystick *SDL_JoystickOpen(int device_index)
|
|||
SDL_memset(joystick->buttons, 0,
|
||||
joystick->nbuttons*sizeof(Uint8));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( joystick ) {
|
||||
|
||||
/* Add joystick to list */
|
||||
++joystick->ref_count;
|
||||
SDL_Lock_EventThread();
|
||||
|
@ -169,7 +172,7 @@ SDL_Joystick *SDL_JoystickOpen(int device_index)
|
|||
/* Skip to next joystick */ ;
|
||||
SDL_joysticks[i] = joystick;
|
||||
SDL_Unlock_EventThread();
|
||||
}
|
||||
|
||||
return(joystick);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue