Fixed rare null pointer dereference
authorSam Lantinga <slouken@libsdl.org>
Mon, 24 Sep 2018 20:31:24 -0700
changeset 12205483789136c52
parent 12204 5486557ca8d9
child 12206 0be7fc59830a
Fixed rare null pointer dereference
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	Mon Sep 24 16:41:55 2018 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Sep 24 20:31:24 2018 -0700
     1.3 @@ -583,7 +583,7 @@
     1.4                                          View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
     1.5                                          View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
     1.6                                          View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
     1.7 -                    					View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
     1.8 +                                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
     1.9                              window.getDecorView().setSystemUiVisibility(flags);        
    1.10                              window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    1.11                              window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    1.12 @@ -1512,6 +1512,10 @@
    1.13                                 int format, int width, int height) {
    1.14          Log.v("SDL", "surfaceChanged()");
    1.15  
    1.16 +        if (SDLActivity.mSingleton == null) {
    1.17 +            return;
    1.18 +        }
    1.19 +
    1.20          int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default
    1.21          switch (format) {
    1.22          case PixelFormat.A_8:
    1.23 @@ -1559,25 +1563,24 @@
    1.24  
    1.25          mWidth = width;
    1.26          mHeight = height;
    1.27 -		int nDeviceWidth = width;
    1.28 -		int nDeviceHeight = height;
    1.29 -		try
    1.30 -		{
    1.31 -			if ( android.os.Build.VERSION.SDK_INT >= 17 )
    1.32 -			{
    1.33 -				android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics();
    1.34 -				mDisplay.getRealMetrics( realMetrics );
    1.35 -				nDeviceWidth = realMetrics.widthPixels;
    1.36 -				nDeviceHeight = realMetrics.heightPixels;
    1.37 -			}
    1.38 -		}
    1.39 -		catch ( java.lang.Throwable throwable ) {}
    1.40 +        int nDeviceWidth = width;
    1.41 +        int nDeviceHeight = height;
    1.42 +        try
    1.43 +        {
    1.44 +            if ( android.os.Build.VERSION.SDK_INT >= 17 )
    1.45 +            {
    1.46 +                android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics();
    1.47 +                mDisplay.getRealMetrics( realMetrics );
    1.48 +                nDeviceWidth = realMetrics.widthPixels;
    1.49 +                nDeviceHeight = realMetrics.heightPixels;
    1.50 +            }
    1.51 +        }
    1.52 +        catch ( java.lang.Throwable throwable ) {}
    1.53  
    1.54 -		Log.v("SDL", "Window size: " + width + "x" + height);
    1.55 -		Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
    1.56 +        Log.v("SDL", "Window size: " + width + "x" + height);
    1.57 +        Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
    1.58          SDLActivity.onNativeResize(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate());
    1.59  
    1.60 -
    1.61          boolean skip = false;
    1.62          int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
    1.63