简体   繁体   English

LibGdx Android游戏在恢复时使用奇怪的键码崩溃(1026)

[英]LibGdx Android Game Crashes on resume with odd keycode (1026)

Our LibGdx project crashes on resume, when running on android. 在Android上运行时,我们的LibGdx项目在恢复时崩溃。

The following trace shows what went wrong. 以下跟踪显示出了问题所在。 But cannot figure out what to do about the problem. 但是无法弄清楚该问题该怎么办。

01-11 18:37:43.643  17046-17046/com.mojo.rainbowrun.android D/AndroidRuntime﹕ Shutting down VM
01-11 18:37:43.643  17046-17046/com.mojo.rainbowrun.android W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41675d88)
01-11 18:37:43.643  17046-17046/com.mojo.rainbowrun.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mojo.rainbowrun.android, PID: 17046
    java.lang.ArrayIndexOutOfBoundsException: length=256; index=1026
            at com.badlogic.gdx.backends.android.AndroidInput.onKey(AndroidInput.java:561)
            at android.view.View.dispatchKeyEvent(View.java:7791)
            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2042)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1512)
            at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1969)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3852)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3558)
            at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3718)
            at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2087)
            at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1781)
            at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1772)
            at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2064)
            at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
            at android.os.MessageQueue.nativePollOnce(Native Method)
            at android.os.MessageQueue.next(MessageQueue.java:138)
            at android.os.Looper.loop(Looper.java:196)
            at android.app.ActivityThread.main(ActivityThread.java:5137)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)
            at dalvik.system.NativeStart.main(Native Method)

Here is a code snippet around line 561 of AndroidInput.java : 这是AndroidInput.java 561行周围的代码段:

            if (keyCode == Keys.BUTTON_CIRCLE) {
                if (keys[Keys.BUTTON_CIRCLE]) {
                    keyCount--;
                    keys[Keys.BUTTON_CIRCLE] = false;
                }
            } else {
                if (keys[e.getKeyCode()]) { // Line 561
                    keyCount--;
                    keys[e.getKeyCode()] = false;
            }

The keys array has 256 entries, so Libgdx isn't expecting a keycode as large as 1026. keys数组具有256个条目,因此Libgdx期望的键码不超过1026。

In Line 561, the if statement has an array, and when the if statement codition executes, You are getting the keycode as the index variable which can lead to an array out of bounds like the Logcat says. 在561行中,if语句具有一个数组,并且当if语句编码执行时,您将得到键代码作为索引变量,这可能导致数组超出Logcat的说明。 If this what it causes the problem, Try changing it and sees if it solves the problem. 如果这是引起问题的原因,请尝试对其进行更改,看看是否可以解决问题。

The if statement in line 561 executes with the else statement. 561行if语句else语句一起执行。 If the first if is false . 如果第一个iffalse Verify if you can change your code in that line and see if this is what really causing your crash, I don't know what e object means because you dind't posted what is his job in your code. 验证您是否可以在该行中更改代码,并查看这是否真正导致崩溃,我不知道e对象的含义,因为您没有在代码中发布他的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM