snowkit / snow

A low level cross platform framework for Haxe. Mac, Windows, Linux, Android, iOS, WebGL.
http://snowkit.org/snow
MIT License
133 stars 35 forks source link

Input.gamepadaxis() crashes the app #55

Closed longears closed 9 years ago

longears commented 9 years ago

Encountered this in Luxe but I think it's an issue in Snow.

class Main extends luxe.Game {
    override function update(dt : Float) {
        for (gamepadNum in 0...1) {
            for (buttonNum in 0...20) {

                // gamepaddown works
                trace('gamepad $gamepadNum button $buttonNum = ${Luxe.input.gamepaddown(gamepadNum, buttonNum)}');

                // gamepadaxis causes crash
                trace('gamepad $gamepadNum axis $buttonNum = ${Luxe.input.gamepadaxis(gamepadNum, buttonNum)}');
            }
        }
    }
}

Crashes when run as a native Mac app:

Main.hx:5: gamepad 0 button 0 = false
[luxe_app quit unexpectedly]

And when run in HTML5: TypeError: _gamepad_state is undefined

Looks like an unexpected null in the gamepad_axis_values map: https://github.com/underscorediscovery/snow/blob/master/snow/input/Input.hx#L155

Input.gamepaddown(...) is working just fine with my gamepad; only gamepadaxis is broken.

(Happens whether or not a gamepad is plugged in. Tested on OSX 10.8.5, using latest version of Luxe and Snow from Github. Using an Xbox 360 gamepad and Tattiebogle driver.)