Fix nullptr crash on android
authorSam Lantinga <slouken@libsdl.org>
Fri, 02 Aug 2019 17:20:00 -0700
changeset 129832b95ace6e7bd
parent 12982 2b00c2a7cec4
child 12984 774ceeac9335
Fix nullptr crash on android

nullcheck the device coming back from InputDevice.getDevice(deviceId) in new code added to sdlactivity.onkey.


java.lang.NullPointerException:
at org.libsdl.app.SDLSurface.onKey (SDLActivity.java:1793)
at android.view.View.dispatchKeyEvent (View.java:13321)
at android.view.ViewGroup.dispatchKeyEvent (ViewGroup.java:1912)
at android.view.ViewGroup.dispatchKeyEvent (ViewGroup.java:1912)
at android.view.ViewGroup.dispatchKeyEvent (ViewGroup.java:1912)
at android.view.ViewGroup.dispatchKeyEvent (ViewGroup.java:1912)
at com.android.internal.policy.DecorView.superDispatchKeyEvent (DecorView.java:685)
at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent (PhoneWindow.java:1869)
at android.app.Activity.dispatchKeyEvent (Activity.java:3447)
at org.libsdl.app.SDLActivity.dispatchKeyEvent (SDLActivity.java:496)

@dang @saml @dave
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Fri Aug 02 17:19:50 2019 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Fri Aug 02 17:20:00 2019 -0700
     1.3 @@ -1825,7 +1825,10 @@
     1.4  
     1.5          if (source == InputDevice.SOURCE_UNKNOWN) {
     1.6              InputDevice device = InputDevice.getDevice(deviceId);
     1.7 -            source = device.getSources();
     1.8 +			if ( device != null )
     1.9 +			{
    1.10 +				source = device.getSources();
    1.11 +			}
    1.12          }
    1.13  
    1.14          if ((source & InputDevice.SOURCE_KEYBOARD) != 0) {