Go to file
Sam Lantinga 257c89727a Fixed bug 3426 - Fixes for joystick related issues
ny00

This report is going to cover three issues, with a suggestion for fixes. For reference, tests were done using an installation of android-x86-5.1-rc1.iso within a VirtualBox session. I've actually used an adapter that accepts up to two Playstation 1/2 controllers.

A ZIP file should be attached, with the following contents:
- The patch file itself.
- Outputs of joysticks lists from testjoystick with different orders (before fixing bug).
- Game controllers database entries (for reference).
--- Different outputs for different platforms may stem from different tools being used; The Android mapping was manually constructed using a previously available mapping as a base.
--- Note that it turns out the Linux mapping is already out there in some form: https://github.com/gabomdq/SDL_GameControllerDB/blob/master/gamecontrollerdb.txt

And so, let's begin listing the issues:

1. While changeset https://hg.libsdl.org/SDL/rev/9b540bea3cf1 has good intentions, it appears to make various input devices being mistakenly detected as SDL joysticks. I got lists of the devices from joysticktest, given in the ZIP file. "badordering.txt" is what I get if the device has been plugged since a reboot of the virtual machine, while I've gotten "goodordering.txt" after hot-plugging the USB adapter. As expected, only in the latter case I could use the controller in the test program (assuming it isn't modified).

To take care of this, I updated pollInputDevices and added the function SDLActivity.isDeviceSDLJoystick, in order to have a better filter. Note that it also checks that the device id is non-negative, since VIRTUAL_KEYBOARD appears to include a SOURCE_DPAD, and I should probably keep accepting it as an SDL_joystick (good if you want, say, to support multiple independent d-pad devices).

I hope the device id filter does not break support for the virtual remote (mentioned in the changeset above).

2. So there's a weird glitch here, where the game controller is reported to have SOURCE_KEYBOARD and SOURCE_JOYSTICK, while each controller button press/release emits a KeyEvent with SOURCE_KEYBOARD only. So obviously any test going over the event's own sources is expected to fail.

It is possible to try and filter by the key code, but then there are the dpad key codes, which can also be emitted by actual PC keyboard's key presses/releases (the arrow keys).

So instead, I just call the newly added isDeviceSDLJoystick function again and check if the input device (not the event) has any source considered to be a joystick/gamepad for us.

3. Finally, if SDL2 properly detects an SDL_Joystick being connected, but it is not opened, then whenever a KeyEvent is received after a button press/release from the same controller, SDLActivity.onNativePadDown/onNativePadUp returns a negative value. In such a case, the onKey handler continues to check for SOURCE_KEYBOARD (and possibly also SOURCE_MOUSE), which is clearly not desired.

And so, in the given patch, the return values of onNativePadDown and onNativePadUp are ignored and "true" is returned either way.

(Note: Maybe the native functions should be modified to have the return value of "void".)

Finally, as another side-note, I've noticed that the various bitwise tests for sources are wrong. For instance, to check if an InputDevice 'device' has source SOURCE_JOYSTICK, the value (device.getSources() & SOURCE_JOYSTICK) should be compared to SOURCE_JOYSTICK, not 0.
However, I think there's enough that this patch covers. At the least, isDeviceSDLJoystick partially solves this.
2016-09-29 16:52:48 -07:00
VisualC audio: Removed internal SDL_audiomem.h and macros. 2016-08-05 01:44:15 -04:00
VisualC-WinRT Merge audio capture work back into the mainline. 2016-08-28 13:36:13 -04:00
Xcode Updated version to 2.0.5 in preparation for release 2016-09-28 22:24:01 -07:00
Xcode-iOS iOS: Updated comment in demo. 2016-09-26 23:09:19 +02:00
acinclude Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
android-project Fixed bug 3426 - Fixes for joystick related issues 2016-09-29 16:52:48 -07:00
build-scripts emscripten-buildbot.sh: exit with an error if configure/make fail. 2016-09-06 12:18:52 -04:00
cmake Fix CMake CMAKE_REQUIRED_FLAGS handling to preserve existing CMake flags required by Emscripten toolchain. 2016-09-13 00:03:50 -07:00
debian Replaced SDL_qsort with public domain code from PDCLib: http://pdclib.e43.eu/ 2016-02-15 03:16:46 -05:00
docs Updated Linux notes on building with Mir and Wayland support. 2016-09-29 12:04:07 -04:00
include Generalized the hint for whether the application gets a mouse event when clicking on the window to activate it, and is now named SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH. 2016-09-29 13:34:49 -07:00
premake Enable SDL_LoadObject on iOS 8+ and tvOS. 2016-09-25 15:02:06 -03:00
src Added debug output for new window events 2016-09-29 16:10:08 -07:00
test Fixed compiling of three test programs with C++. 2016-09-21 23:06:38 +02:00
visualtest Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
.hgignore audio: Initial bits to enable audio capture support. 2016-08-01 00:18:56 -04:00
Android.mk Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
BUGS.txt BUGS.txt: Bugzilla supports SSL; changed link to https:// ... 2016-08-01 13:36:43 -04:00
CMakeLists.txt Updated version to 2.0.5 in preparation for release 2016-09-28 22:24:01 -07:00
COPYING.txt Updated copyright to 2016 2016-01-02 10:10:34 -08:00
CREDITS.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
INSTALL.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
Makefile.in wayland: Build own version of core protocol 2016-06-23 18:39:05 +08:00
Makefile.minimal Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
Makefile.pandora Pandora: Fixed referring to no more existing atomic source file in Makefile. 2016-07-19 21:01:13 +02:00
Makefile.psp PSP: Added missing object for generic TLS to Makefile. 2016-02-13 17:34:14 +01:00
Makefile.wiz Pandora: Updated SDL version in Makefile. 2016-07-19 21:01:30 +02:00
README-SDL.txt Another commit to test revision control. 2016-03-08 20:26:26 -05:00
README.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
SDL2.spec.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
TODO.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
VisualC.html Fixed two typos in documentation. 2016-01-12 22:23:53 +01:00
WhatsNew.txt Updated some header comments and iOS documentation to better clarify high-dpi / retina support and screen-coordinate sizes versus pixel sizes. 2015-12-31 21:16:43 -04:00
autogen.sh Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
cmake_uninstall.cmake.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
configure Updated version to 2.0.5 in preparation for release 2016-09-28 22:24:01 -07:00
configure.in Updated version to 2.0.5 in preparation for release 2016-09-28 22:24:01 -07:00
sdl2-config.cmake.in Fixed typo in sdl2-config.cmake.in (thanks, Rafal!). 2015-12-28 23:29:11 -05:00
sdl2-config.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
sdl2.m4 Fixed bug 3429 - Update AM_PATH_SDL2() to also check for SDL2.framework 2016-09-29 16:37:08 -07:00
sdl2.pc.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00

README.txt

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.


                         Simple DirectMedia Layer

                                  (SDL)

                                Version 2.0

---
http://www.libsdl.org/

Simple DirectMedia Layer is a cross-platform development library designed
to provide low level access to audio, keyboard, mouse, joystick, and graphics
hardware via OpenGL and Direct3D. It is used by video playback software,
emulators, and popular games including Valve's award winning catalog
and many Humble Bundle games.

More extensive documentation is available in the docs directory, starting
with README.md

Enjoy!
	Sam Lantinga				(slouken@libsdl.org)