Commit 516aaa5d authored by Ryan C. Gordon's avatar Ryan C. Gordon

Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404358
parent 9a2b0cfb
...@@ -114,13 +114,17 @@ SDL_JoystickOpen(int device_index) ...@@ -114,13 +114,17 @@ SDL_JoystickOpen(int device_index)
/* Create and initialize the joystick */ /* Create and initialize the joystick */
joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick)); joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick));
if (joystick != NULL) { if (joystick == NULL) {
SDL_OutOfMemory();
return NULL;
}
SDL_memset(joystick, 0, (sizeof *joystick)); SDL_memset(joystick, 0, (sizeof *joystick));
joystick->index = device_index; joystick->index = device_index;
if (SDL_SYS_JoystickOpen(joystick) < 0) { if (SDL_SYS_JoystickOpen(joystick) < 0) {
SDL_free(joystick); SDL_free(joystick);
joystick = NULL; return NULL;
} else { }
if (joystick->naxes > 0) { if (joystick->naxes > 0) {
joystick->axes = (Sint16 *) SDL_malloc joystick->axes = (Sint16 *) SDL_malloc
(joystick->naxes * sizeof(Sint16)); (joystick->naxes * sizeof(Sint16));
...@@ -143,27 +147,22 @@ SDL_JoystickOpen(int device_index) ...@@ -143,27 +147,22 @@ SDL_JoystickOpen(int device_index)
|| ((joystick->nbuttons > 0) && !joystick->buttons)) { || ((joystick->nbuttons > 0) && !joystick->buttons)) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_JoystickClose(joystick); SDL_JoystickClose(joystick);
joystick = NULL; return NULL;
} }
if (joystick->axes) { if (joystick->axes) {
SDL_memset(joystick->axes, 0, SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
joystick->naxes * sizeof(Sint16));
} }
if (joystick->hats) { if (joystick->hats) {
SDL_memset(joystick->hats, 0, SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
joystick->nhats * sizeof(Uint8));
} }
if (joystick->balls) { if (joystick->balls) {
SDL_memset(joystick->balls, 0, SDL_memset(joystick->balls, 0,
joystick->nballs * sizeof(*joystick->balls)); joystick->nballs * sizeof(*joystick->balls));
} }
if (joystick->buttons) { if (joystick->buttons) {
SDL_memset(joystick->buttons, 0, SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8));
joystick->nbuttons * sizeof(Uint8));
} }
}
}
if (joystick) {
/* Add joystick to list */ /* Add joystick to list */
++joystick->ref_count; ++joystick->ref_count;
SDL_Lock_EventThread(); SDL_Lock_EventThread();
...@@ -171,7 +170,7 @@ SDL_JoystickOpen(int device_index) ...@@ -171,7 +170,7 @@ SDL_JoystickOpen(int device_index)
/* Skip to next joystick */ ; /* Skip to next joystick */ ;
SDL_joysticks[i] = joystick; SDL_joysticks[i] = joystick;
SDL_Unlock_EventThread(); SDL_Unlock_EventThread();
}
return (joystick); return (joystick);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment