Libgdx IllegalArgumentException:Android LWP上的错误位置8/0

时间:2018-03-26 07:38:19

标签: java android libgdx

有时在我的Android动态壁纸上我在RESIZE上遇到此异常:IllegalArgumentException: Bad position 8/0

最新的libgdx

java.lang.IllegalArgumentException: Bad position 8/0


at java.nio.Buffer.position(Buffer.java:249)
at com.badlogic.gdx.graphics.glutils.VertexArray.bind(VertexArray.java:118)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:391)
at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:382)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:490)
at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:460)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SpriteBatch.java:977)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.setProjectionMatrix(SpriteBatch.java:1049)
at hu.lacas.newalienlwp.Renderer.resizeBatch(Renderer.kt:844)
at hu.lacas.newalienlwp.Renderer.access$resizeBatch(Renderer.kt:44)
at hu.lacas.newalienlwp.Renderer$resize$1.run(Renderer.kt:828)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

源代码

    @override fun resize(width: Int, height: Int) {
        camera.viewportHeight = Gdx.graphics.height.toFloat()
        camera.viewportWidth = Gdx.graphics.width.toFloat()
        mOrientation = if (camera.viewportHeight < camera.viewportWidth) LiveWallpaper.ORIENTATION_LANDSCAPE else LiveWallpaper.ORIENTATION_PORTRAIT
        camera.fieldOfView = (if (mOrientation != LiveWallpaper.ORIENTATION_LANDSCAPE) 27 else 20).toFloat()
        camera.update()

        handler.postDelayed({
            resizeBatch()
        }, 900)

    }


    private fun resizeBatch() {
        val viewportWidth = Gdx.graphics.width
        val viewportHeight = Gdx.graphics.height
        if (camera2D == null) camera2D = OrthographicCamera()
        camera2D?.setToOrtho(false, viewportWidth.toFloat(), viewportHeight.toFloat())
        camera2D?.update()
        spriteBatch!!.projectionMatrix = camera2D?.combined

        Objects.textureRegionScanlineFullScreen.setRegion(0, 0, Gdx.graphics.width, Gdx.graphics.height)
    }

看起来问题就在这里:

- &GT; spriteBatch !!。projectionMatrix = camera2D?.combined

这个例外有时会出现......所以不太明白发生了什么。我用900毫秒创建了这个处理程序,因为当不存在时,会显示更多的异常..什么是正在进行? Libgdx还没有加载矩阵吗?

0 个答案:

没有答案