GLBasic forum

Main forum => Bug Reports => Topic started by: bigsofty on 2016-Feb-26

Title: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: bigsofty on 2016-Feb-26
Seems to be a problem with GETNUMJOYSTICKS() if you turn the gamepad on (I'm using a wireless 360 gamepad) after your app has started, it's always zero. I could tell people that it will require a restart if their gamepad is not recognised but this feels a bit clumsy.

Any tips on how to avoid this?
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: Ian Price on 2016-Feb-27
IIRC this was always a problem on Windows (historically) in general; f you plugged in a joypad after running any program it fails to register. Had this issue with MAME BITD. Don't know if it's sorted iin newer versions of Windows though - I haven't used a pad on a pc in years.
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: spacefractal on 2016-Feb-27
Im confirm, its not a Windows issue. Im can see the way the function is used in the source code.

Take a look into this one:
http://stackoverflow.com/questions/21224023/why-does-sdl-numjoysticks-never-update

in glbasic, NumJoysticks variable is only set on init, and then SDL_NumJoysticks() is newer rechecked for any changes at all, which means its does not detect a changed connection at all.

MAME might have been did the same thing.

On Windows its not a big issue at all, but this can been more happens much more on iOS example. This feature is required to been checked for MFi controller support and is included in GameInput Api (etc a game should pause on a change example).

Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: Ian Price on 2016-Feb-27
I note you changed your original post, which stated -

Quote
Yes, its a Windows issue. Something that can been checked on both Android and iOS. on iOS, MFI controllers might also been disconneted or connected while a app is running and require to perform a pause or such when that happens. Howover its was quite easy on iOS.

on Windows, connections is property only checked when DirectInput is init. Thun its impossible to fix it.

So dont except this can been fixed, and if its does then its would been inside GameInput Api me thinks.

It would have been best to strikethough your original commet and state that on investigation it looks like it can be fixed.

Obviously Windows has changed since I last used a pad. Hopefully it can be fixed in GLB. :)

As for MAME - no the issues back then was windows, as that never showed the joypad after it was connected after boot up either. Like I said, newer Windows versions probably fixed this.


[EDIT] But yeah, perhaps neither MAME or GLB bothered checking after initial start-up.
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: spacefractal on 2016-Feb-27
yes, im should property posted a new post, but im was not excepted you was quite fast to post it, because im changed it quite very fast after the original post, why im edited it after checking the source code.

btw game like Witcher 3 does not have the issue, but many games does not check status after init.
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: MrTAToad on 2016-Feb-27
Yes, most games dont check to see if the number of joysticks changes - its not particularly easy to do as such (which is probably one of the reasons most dont bother).

SDL2 does have a specific event for joysticks being added (or removed) whilst a program is running.  Note that SDL2 treats joysticks separately from game controllers
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: bigsofty on 2016-Feb-28
OK, that's clear now. It's more of an annoyance than a bug I suppose but if it was possible to do a SDL_NumJoysticks() from a command or an inlined sub then that would be better than an app restart. I'll look into this further when my todo list shrinks a bit.

Thanks for your input guys.
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: bigsofty on 2016-Apr-15
Still looking into a solution to this. I think GLB is using DirectInput on Windows, if so, then the following article suggests using a callback for windows messaging that activates if something is plugged in or removed...

http://web.archive.org/web/20141211154922/http://www.spellofplay.com/blogs/hobbe/detecting-if-game-pad-plugged-or-removed.html
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: UBERmonkeybot on 2016-Sep-25
Bigsofty did you get anywhere with this issue?
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: Kitty Hello on 2016-Sep-28
You have to restart the app. (shellcmd)
Title: Re: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started
Post by: UBERmonkeybot on 2016-Sep-28
Thanks kitty.