libgdx/libgdx

com.badlogic.gdx.backends.android npe

Jun19 opened this issue · 1 comments

Please ensure you have given all the following requested information in your report.

Issue details

I just initialized and then a crash occurred

Reproduction steps/code

 val cfg = AndroidApplicationConfiguration()
    cfg.r = 8.also { cfg.a = it }.also { cfg.b = it }.also { cfg.g = it }
    spineBoyView = initializeForView(spineBoy, cfg)
    spineBoyView?.setBackgroundColor(
        ContextCompat.getColor(
            this@SpineActivity,
            R.color.green_94f7c7
        )
    )
    if (spineBoyView is SurfaceView) {
        val glView = spineBoyView as SurfaceView
        glView.holder.setFormat(PixelFormat.TRANSLUCENT)
        glView.setZOrderOnTop(true)
    }
    addSpineView()

private fun addSpineView() {
    val windowManager = windowManager
    layoutParams = WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
        PixelFormat.TRANSLUCENT
    )
    layoutParams?.gravity = Gravity.TOP or Gravity.START
    val displayMetrics = resources.displayMetrics
    left = 0
    right = displayMetrics.widthPixels
    top = 0
    bottom = displayMetrics.heightPixels
    val scale = 2
    layoutParams?.run {
        width = dp2Px((144 * scale).toFloat())
        height = dp2Px((144 * scale).toFloat())
        x = 0
        y = 0
        windowManager.addView(spineBoyView, this)
    }

}

Version of libGDX and/or relevant dependencies

implementation 'com.esotericsoftware.spine:spine-libgdx:4.1.0'
implementation 'com.badlogicgames.gdx:gdx-backend-android:1.12.1'
implementation 'com.badlogicgames.gdx:gdx:1.12.1'

Stacktrace

           E  FATAL EXCEPTION: GLThread 35
                                                                                                    Process: com.xxx., PID: 19962
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.DisplayCutout android.view.WindowInsets.getDisplayCutout()' on a null object reference
                                                                                                    	at com.badlogic.gdx.backends.android.AndroidGraphics.updateSafeAreaInsets(AndroidGraphics.java:666)
                                                                                                    	at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceCreated(AndroidGraphics.java:327)
                                                                                                    	at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1541)
                                                                                                    	at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)

Please select the affected platforms

  • [ √] Android
  • iOS
  • HTML/GWT
  • Windows
  • Linux
  • macOS

Please follow https://libgdx.com/wiki/articles/getting-help guidelines including requesting help on channels such as Discord and providing self contained executable code. Closing for now, feel free to reopen after following guidelines if you still feel it's an issue.