SDL2 Windows Joysticks failing to load on start-up

Hi,

In Windows (tested both in XP and 7), if I have a USB controller
plugged in before starting my SDL2-based game, the game fails to
detect the joystick upon start-up. I’ve traced the error to
SDL_dxjoystick.c line 405:

—snip—
result =
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
InputDevice, SDL_HelperWindow,
DISCL_EXCLUSIVE |
DISCL_BACKGROUND);
—snap

The above call fails when starting the game; however, it works when
called again in the options menu of the game. The method I am calling
in my game is Joystick::initJoystick(), and fails at
SDL_JoystickOpen() at:

Would anyone know why this is failing on start-up of the game, but not
when it is loaded?

I’m afraid I am not familiar with Windows programming (much less DX).
Also, I do not have this problem in Mac OS X or Linux.

Thanks for any help!
D

Please forgive me for replying to myself. I have new information.

One of our Windows developers found that initializing the joystick
system after the video system will make the error go away. Is this
what is supposed to happen with SDL2? or is just good or common
practice anyways? Having to load the subsystems in a specific order
wasn’t something we had to worry about with SDL 1.2.

Also, I found this old mailing list patch for 1.2 that looks like it
may be the same problem:

http://lists.libsdl.org/pipermail/sdl-libsdl.org/2004-October/046575.html

Maybe?

Thanks,
DOn Mon, Jul 30, 2012 at 8:07 PM, D B <@D_B> wrote:

Hi,

In Windows (tested both in XP and 7), if I have a USB controller
plugged in before starting my SDL2-based game, the game fails to
detect the joystick upon start-up. I’ve traced the error to
SDL_dxjoystick.c line 405:

—snip—
result =
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
InputDevice, SDL_HelperWindow,
DISCL_EXCLUSIVE |
DISCL_BACKGROUND);
—snap

The above call fails when starting the game; however, it works when
called again in the options menu of the game. The method I am calling
in my game is Joystick::initJoystick(), and fails at
SDL_JoystickOpen() at:

https://code.google.com/p/bitfighter/source/browse/zap/Joystick.cpp#160

Would anyone know why this is failing on start-up of the game, but not
when it is loaded?

I’m afraid I am not familiar with Windows programming (much less DX).
Also, I do not have this problem in Mac OS X or Linux.

Thanks for any help!
D

I think it’s because DirectX/DInput requires some sort of context to
initialize the joystick information into it. Can anyone with more
knowledge confirm this? If so, should it be mentioned in the wiki
somewhere?On Wed, Aug 1, 2012 at 1:39 AM, D B wrote:

Please forgive me for replying to myself. I have new information.

One of our Windows developers found that initializing the joystick
system after the video system will make the error go away. Is this
what is supposed to happen with SDL2? or is just good or common
practice anyways? Having to load the subsystems in a specific order
wasn’t something we had to worry about with SDL 1.2.

Also, I found this old mailing list patch for 1.2 that looks like it
may be the same problem:

http://lists.libsdl.org/pipermail/sdl-libsdl.org/2004-October/046575.html

Maybe?

Thanks,
D

On Mon, Jul 30, 2012 at 8:07 PM, D B wrote:

Hi,

In Windows (tested both in XP and 7), if I have a USB controller
plugged in before starting my SDL2-based game, the game fails to
detect the joystick upon start-up. I’ve traced the error to
SDL_dxjoystick.c line 405:

—snip—
result =
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
InputDevice,
SDL_HelperWindow,
DISCL_EXCLUSIVE |
DISCL_BACKGROUND);
—snap

The above call fails when starting the game; however, it works when
called again in the options menu of the game. The method I am calling
in my game is Joystick::initJoystick(), and fails at
SDL_JoystickOpen() at:

https://code.google.com/p/bitfighter/source/browse/zap/Joystick.cpp#160

Would anyone know why this is failing on start-up of the game, but not
when it is loaded?

I’m afraid I am not familiar with Windows programming (much less DX).
Also, I do not have this problem in Mac OS X or Linux.

Thanks for any help!
D


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I used to test directx to evaluate it. I remember that it needs
directinput to enum and find every device. After that you tell is about the
device you will use, and then which controls to use and where the reports
will be. He’s right it’s a building proccess. Most people take the first
joystick found and go with it. If there is no choice then this is like that
i think. There is a definate order to it.

I only have theory. If it works that way then the video does the the first
or second part where without it there is a fail. I wish i had more for you.
If someone looks at the code they can tell more. (sdl2)On Wed, Aug 1, 2012 at 12:39 AM, D B wrote:

Please forgive me for replying to myself. I have new information.

One of our Windows developers found that initializing the joystick
system after the video system will make the error go away. Is this
what is supposed to happen with SDL2? or is just good or common
practice anyways? Having to load the subsystems in a specific order
wasn’t something we had to worry about with SDL 1.2.

Also, I found this old mailing list patch for 1.2 that looks like it
may be the same problem:

http://lists.libsdl.org/pipermail/sdl-libsdl.org/2004-October/046575.html

Maybe?

Thanks,
D

On Mon, Jul 30, 2012 at 8:07 PM, D B wrote:

Hi,

In Windows (tested both in XP and 7), if I have a USB controller
plugged in before starting my SDL2-based game, the game fails to
detect the joystick upon start-up. I’ve traced the error to
SDL_dxjoystick.c line 405:

—snip—
result =
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
InputDevice,
SDL_HelperWindow,
DISCL_EXCLUSIVE |
DISCL_BACKGROUND);
—snap

The above call fails when starting the game; however, it works when
called again in the options menu of the game. The method I am calling
in my game is Joystick::initJoystick(), and fails at
SDL_JoystickOpen() at:

https://code.google.com/p/bitfighter/source/browse/zap/Joystick.cpp#160

Would anyone know why this is failing on start-up of the game, but not
when it is loaded?

I’m afraid I am not familiar with Windows programming (much less DX).
Also, I do not have this problem in Mac OS X or Linux.

Thanks for any help!
D


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

OK. I looks like this was my fault.

Note to self: SDL_Init(0) must be called before initializing any of
the subsystems…

Thanks for your time,
DOn Tue, Jul 31, 2012 at 11:39 PM, D B <@D_B> wrote:

Please forgive me for replying to myself. I have new information.

One of our Windows developers found that initializing the joystick
system after the video system will make the error go away. Is this
what is supposed to happen with SDL2? or is just good or common
practice anyways? Having to load the subsystems in a specific order
wasn’t something we had to worry about with SDL 1.2.

Also, I found this old mailing list patch for 1.2 that looks like it
may be the same problem:

http://lists.libsdl.org/pipermail/sdl-libsdl.org/2004-October/046575.html

Maybe?

Thanks,
D

On Mon, Jul 30, 2012 at 8:07 PM, D B <@D_B> wrote:

Hi,

In Windows (tested both in XP and 7), if I have a USB controller
plugged in before starting my SDL2-based game, the game fails to
detect the joystick upon start-up. I’ve traced the error to
SDL_dxjoystick.c line 405:

—snip—
result =
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
InputDevice, SDL_HelperWindow,
DISCL_EXCLUSIVE |
DISCL_BACKGROUND);
—snap

The above call fails when starting the game; however, it works when
called again in the options menu of the game. The method I am calling
in my game is Joystick::initJoystick(), and fails at
SDL_JoystickOpen() at:

https://code.google.com/p/bitfighter/source/browse/zap/Joystick.cpp#160

Would anyone know why this is failing on start-up of the game, but not
when it is loaded?

I’m afraid I am not familiar with Windows programming (much less DX).
Also, I do not have this problem in Mac OS X or Linux.

Thanks for any help!
D