SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL loads wrong controller definition from gamecontrolllerdb

Open sydarn opened this issue 1 year ago • 4 comments

Hi,

I noticed what I think is a bug in how controller definitions are loaded from gamecontrollerdb. Attached is the gamecontrollerdb I am using, it consists of upstream appended with our own definitions: gamecontrollerdb.txt

Here is the symptom:

rgb10max3:~ # grep 19009b4d4b480000 /storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt 
19009b4d4b4800000111000000010000,retrogame_joypad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:b15,dpdown:b14,dpright:b16,dpup:b13,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,
rgb10max3:~ # sdljoytest 
Sys_InitInput: Compiled with SDL version 2.30.3
Sys_InitInput: Linked   with SDL version 2.30.3
Sys_InitInput: SDL2 joystick subsystem init
Sys_InitInput: Loading /storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt
Sys_InitInput: SDL_GameControllerAddMappingsFromFile() added 1 controller maps
Sys_InitInput: Joystick subsytem - Found 1 joysticks at startup
Joystick 0 name 'retrogame_joypad'
Joystick 0 is a game controller
Joystick 0 Axes 04 / Buttons 17 / Hats 00 / Balls 00
Joystick 0 Instance id 0
Joystick 0 Guid 19009b4d4b4800000111000000010000
Opened gamepad device index 0 (RetroGame Joypad)
        axes: 4
     buttons: 17
 instance id: 0
        guid: 19009b4d4b4800000111000000010000
     mapping: 19009b4d4b4800000111000000010000,RetroGame Joypad,a:b1,b:b0,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux,
..................
rgb10max3:~ # grep -r "RetroGame Joypad" /storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt 
190000004b4800000111000000010000,RetroGame Joypad,a:b1,b:b0,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux,

My joystick is called retrogame_joypad and has a uniqe GUID, but instead of loading that it loads another definition called RetroGame Joypad which has a different GUID.

sydarn avatar Jun 23 '24 19:06 sydarn

Hmm, can you debug what's happening?

I created a gamecontrollerdb.txt with the following lines:

03000000b40400001224000000000000,Flydigi 2.4G B,platform:Windows,a:b1,b:b2,back:b11,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b0,leftshoulder:b7,leftstick:b13,lefttrigger:b9,leftx:a0,lefty:a1,misc1:b3,rightshoulder:b8,rightstick:b14,righttrigger:b10,rightx:a3,righty:a4,start:b12,x:b4,y:b5,
030029c5b40400001224000000000000,Flydigi 2.4G A,platform:Windows,a:b1,b:b2,back:b11,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b0,leftshoulder:b7,leftstick:b13,lefttrigger:b9,leftx:a0,lefty:a1,misc1:b3,rightshoulder:b8,rightstick:b14,righttrigger:b10,rightx:a3,righty:a4,start:b12,x:b4,y:b5,

No matter what order I put them in, my controller always used entry A, with the more complete GUID.

slouken avatar Jun 24 '24 00:06 slouken

If I remove the RetroGame Joypad from upstream it works.

So controller mapping isn't really picked from the GUID then... isn't it supposed to be? that kind defies the point of a unique identifier.

I am just going to patch out the upstream entry for now, but would like some clarity on if this is expected behavior or not?

sydarn avatar Jun 24 '24 06:06 sydarn

This isn't expected behavior. As you see from my test above, the more specific mapping (Flydigit 2.4G A) is always selected, as expected.

Can you reduce gamecontrollerdb.txt to just the retrogame entries and remove all the mappings from SDL_gamecontrollerdb.h and run a debugger to find out why the wrong entry is being picked for your controller?

slouken avatar Jun 24 '24 11:06 slouken

Maybe the same bug: my file has a single line:

0300c16ad62000000120000001010000,PowerA Xbox Series X Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,

SDL loads it, but fails to find the mapping.

I copied this entry from gamecontrollerdb.txt, but curiously it has a different GUID there: 03000000d62000000b20000001010000

RenaKunisaki avatar Jun 25 '24 23:06 RenaKunisaki

No matter what order I put them in, my controller always used entry A, with the more complete GUID.

This is not the case for me. If retrogame_joypad is before RetroGame Joypad, it picks RetroGame Joypad. If retrogame_joypad is last it correctly picks that one. I just used the simplified DB with those two entries:

190000004b4800000111000000010000,RetroGame Joypad,a:b1,b:b0,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux,
19009b4d4b4800000111000000010000,retrogame_joypad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:b15,dpdown:b14,dpright:b16,dpup:b13,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,

This DB leads to correct behavior, the other way around to incorrect behavior.

sydarn avatar Jul 01 '24 15:07 sydarn

Are you able to debug and find out why that is? If not, are you available to pair program over Zoom?

slouken avatar Jul 01 '24 22:07 slouken

Are you able to debug and find out why that is? If not, are you available to pair program over Zoom?

I am foremost time limited, is there any straight forward way to increase and get relevant log output? Or can I build SDL in an certain way? We updated to SDL2.30.4 and problem persists. If you have instructions or patch I can easily build and test with that.

sydarn avatar Jul 02 '24 10:07 sydarn

Interesting. I am able to reproduce this in SDL2, but not in SDL3. I'm investigating.

slouken avatar Jul 03 '24 19:07 slouken

Sorry for the back and forth, it turns out this was fixed a while ago but the fix hadn't made it into the official release. It'll be in today's release, fixed in e5024fae3.

Thanks!

slouken avatar Jul 03 '24 20:07 slouken

This is fixed in the latest release: https://github.com/libsdl-org/SDL/releases/tag/release-2.30.5

slouken avatar Jul 03 '24 21:07 slouken