mirror of https://github.com/encounter/SDL.git
commit 1170112da3776fdb06425f62d57b63144c33dc51
Author: James Zipperer <james.zipperer@synapse.com> Date: Sun Aug 21 01:19:19 2016 -0700 bugfix for controller / joystick add / remove being in the event queue at the same time
This commit is contained in:
parent
e79f00097a
commit
c69bce6774
|
@ -222,7 +222,19 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
|
||||||
SDL_GameController *controllerlist = SDL_gamecontrollers;
|
SDL_GameController *controllerlist = SDL_gamecontrollers;
|
||||||
while (controllerlist) {
|
while (controllerlist) {
|
||||||
if (controllerlist->joystick->instance_id == event->jdevice.which) {
|
if (controllerlist->joystick->instance_id == event->jdevice.which) {
|
||||||
|
SDL_Event peeped;
|
||||||
SDL_Event deviceevent;
|
SDL_Event deviceevent;
|
||||||
|
|
||||||
|
/* If there is an existing add event in the queue, it
|
||||||
|
* needs to be modified to have the right value for which,
|
||||||
|
* because the number of controllers in the system is now
|
||||||
|
* one less.
|
||||||
|
*/
|
||||||
|
if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED) > 0) {
|
||||||
|
peeped.jdevice.which--;
|
||||||
|
SDL_PushEvent(&peeped);
|
||||||
|
}
|
||||||
|
|
||||||
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
|
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
|
||||||
deviceevent.cdevice.which = event->jdevice.which;
|
deviceevent.cdevice.which = event->jdevice.which;
|
||||||
SDL_PushEvent(&deviceevent);
|
SDL_PushEvent(&deviceevent);
|
||||||
|
|
|
@ -295,6 +295,18 @@ MaybeRemoveDevice(const char *path)
|
||||||
event.type = SDL_JOYDEVICEREMOVED;
|
event.type = SDL_JOYDEVICEREMOVED;
|
||||||
|
|
||||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||||
|
SDL_Event peeped;
|
||||||
|
|
||||||
|
/* If there is an existing add event in the queue, it
|
||||||
|
* needs to be modified to have the right value for which,
|
||||||
|
* because the number of controllers in the system is now
|
||||||
|
* one less.
|
||||||
|
*/
|
||||||
|
if ( SDL_PeepEvents(&peeped, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED) > 0) {
|
||||||
|
peeped.jdevice.which--;
|
||||||
|
SDL_PushEvent(&peeped);
|
||||||
|
}
|
||||||
|
|
||||||
event.jdevice.which = item->device_instance;
|
event.jdevice.which = item->device_instance;
|
||||||
if ( (SDL_EventOK == NULL) ||
|
if ( (SDL_EventOK == NULL) ||
|
||||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||||
|
|
Loading…
Reference in New Issue