【问题标题】:Android Libgdx - Sigsegv 11 error on real device but no crash on emulatorAndroid Libgdx - 真实设备上的 Sigsegv 11 错误,但模拟器上没有崩溃
【发布时间】:2018-09-13 01:12:13
【问题描述】:

我目前正在尝试在 android 上使用 libgdx 制作应用程序。

该应用程序在 android studio 的模拟器上运行良好,但是当我使用 library box2d 执行 world.destroy(body) 时,我的真实手机崩溃了。 更准确地说,在游戏执行期间,应用程序在碰撞后破坏了 2 个主体,就像它应该做的那样,但在 1 秒后应用程序崩溃。

这是我的碰撞监听器的代码。

@Override
public void beginContact(Contact contact) {

    Body a = contact.getFixtureA().getBody();
    Body b = contact.getFixtureB().getBody();

    if ((BodyUtils.bodyIsWater(b) && BodyUtils.bodyIsEnemy(a))|| (BodyUtils.bodyIsEnemy(b) && BodyUtils.bodyIsWater(a))){
            if (!remove.contains(a)) {
                remove.add(a);
            }
            if (!remove.contains(b)) {
                remove.add(b);
            }
            iswater = false;
    }
    else if(BodyUtils.bodyIsGround(b) && BodyUtils.bodyIsWater(a)){
        if(!remove.contains(a)) {
            remove.add(a);
        }
        iswater=false;
    }
    else if(BodyUtils.bodyIsGround(a) && BodyUtils.bodyIsWater(b)){
        if(!remove.contains(b)) {
            remove.add(b);
        }
        iswater=false;
    }
    a=null;
    b=null;
}

关于代码的注释:水是射杀敌人的子弹。 remove 就是arraylist。

这是我的 act 方法的代码,它破坏了我要销毁的 body 数组列表中的 body (碰撞方法,但要销毁的 body 进入 arraylist )。 destroy 调用进入 for 循环。

@Override
public void act(float delta) {
    super.act(delta);

    // Fixed timestep
    accumulator += delta;

    while (accumulator >= delta) {
        world.step(TIME_STEP, 10, 10);
        accumulator -= TIME_STEP;
    }

    for (int i = 0; i < remove.size(); i++) {
        world.destroyBody(remove.get(i));
        remove.remove(i);
        /*for (int n = 0; i < y.getJointList().size; n++){
            world.destroyJoint(y.getJointList().get(n).joint);
        }*/
    }

    if(add%100==0 && !iswater) {
        Array<Body> bodies = new Array<Body>(world.getBodyCount());
        world.getBodies(bodies);

        for (Body body : bodies) {
            update(body);
        }
    }
    if(add%80==0){
        createEnemy();
    }

    add++;

}

这里是更新方法的内容:

private void update(Body body) {
    if (BodyUtils.bodyIsEnemy(body) && !iswater) {
        EnemyUserData z = (EnemyUserData) body.getUserData();
        Vector2 m=body.getPosition();
        if(m.x<23f){
            createWater(z,m);
            iswater=true;
        }
    }
}

首先,我试图找出问题出在哪里,我发现如果 a 没有破坏身体,应用程序就不会崩溃。所以知道我知道destroy函数会使应用程序崩溃。

这是 Sigsegv 日志:

04-03 19:01:50.068 25361-25404/com.mygdx.game A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7a99fd63c0 in tid 25404 (GLThread 3290)

                                                  [ 04-03 19:01:50.076   402:  402 W/         ]
                                                  debuggerd: handling request: pid=25361 uid=10171 gid=10171 tid=25404
04-03 19:01:50.174 25501-25501/? A/DEBUG: *** *** *** *** *** *** *** *** 
*** *** *** *** *** *** *** ***
04-03 19:01:50.174 25501-25501/? A/DEBUG: Build fingerprint: 'HUAWEI/PRA-LX1/HWPRA-H:7.0/HUAWEIPRA-LX1/C432B196:user/release-keys'
04-03 19:01:50.174 25501-25501/? A/DEBUG: Revision: '0'
04-03 19:01:50.174 25501-25501/? A/DEBUG: ABI: 'arm64'
04-03 19:01:50.174 25501-25501/? A/DEBUG: pid: 25361, tid: 25404, name: GLThread 3290  >>> com.mygdx.game <<<
04-03 19:01:50.174 25501-25501/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7a99fd63c0
04-03 19:01:50.174 25501-25501/? A/DEBUG:     x0   0000007a99fd63c0  x1   00000000000000b8  x2   0000007899f841c0  x3   0000000000000002
04-03 19:01:50.174 25501-25501/? A/DEBUG:     x4   0000000000000001  x5   0000000000000001  x6   0000000000000000  x7   0000000000000000
04-03 19:01:50.174 25501-25501/? A/DEBUG:     x8   000000789a2e8098  x9   0000000000000000  x10  0000000000000001  x11  0000000000000001
04-03 19:01:50.174 25501-25501/? A/DEBUG:     x12  000000789a91d718  x13  000000789a91d7b4  x14  00000078b7ab1150  x15  0000000000000060
04-03 19:01:50.174 25501-25501/? A/DEBUG:     x16  000000789a2e7a18  x17  000000789a2b99d8  x18  0000000000000001  x19  0000007899f841c0
04-03 19:01:50.175 25501-25501/? A/DEBUG:     x20  00000078b6888760  x21  0000007899f84200  x22  0000000000000006  x23  00000078b0a86fa0
04-03 19:01:50.175 25501-25501/? A/DEBUG:     x24  0000000000000048  x25  604eae760b11fb4a  x26  00000078b80d5698  x27  00000078b80d5600
04-03 19:01:50.175 25501-25501/? A/DEBUG:     x28  000000789a91d7b0  x29  000000789a91d6d0  x30  000000789a2bd004
04-03 19:01:50.175 25501-25501/? A/DEBUG:     sp   000000789a91d6a0  pc   000000789a2b9a34  pstate 0000000080000000
04-03 19:01:50.180 25501-25501/? A/DEBUG: backtrace:
04-03 19:01:50.180 1295-1316/? I/Bluetooth_framework: BluetoothManagerService:Message: 401
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #00 pc 000000000001ba34  /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (_ZN16b2BlockAllocator8AllocateEi+92)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #01 pc 000000000001f000  /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (_ZN7b2World10CreateBodyEPK9b2BodyDef+48)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #02 pc 000000000002f6d0  /data/app/com.mygdx.game-1/lib/arm64/libgdx-box2d.so (Java_com_badlogic_gdx_physics_box2d_World_jniCreateBody+160)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #03 pc 00000000000db790  /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #04 pc 00000000000d21b4  /system/lib64/libart.so (art_quick_invoke_stub+580)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #05 pc 00000000000dee80  /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+204)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #06 pc 000000000028cbf0  /system/lib64/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+312)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #07 pc 0000000000286cac  /system/lib64/libart.so (_ZN3art11interpreter6DoCallILb1ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+444)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #08 pc 00000000005556e4  /system/lib64/libart.so (MterpInvokeDirectRange+384)
04-03 19:01:50.181 25501-25501/? A/DEBUG:     #09 pc 00000000000c4f94  /system/lib64/libart.so (ExecuteMterpImpl+15252)


                                      [ 04-03 19:01:50.536   402:  402 W/         ]
                                      debuggerd: resuming target 25361

我还测试了一个与我的手机具有相同 android 版本的模拟器,它可以工作。 (它是版本 7 api 24)。所以这不是问题。

ps:我不会摧毁一个身体两次(我已经设置了一些条件来避免它)。

我是 libgdx 的菜鸟,请帮助

编辑:在“Subrata M”的评论中回答一个问题,如果我在更新和 createEnemy() 之后放置 destroy 方法,这里是 logcat。

04-03 20:26:59.973 29708-29747/com.mygdx.game A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7a9a07b400 in tid 29747 (GLThread 3385)
04-03 20:26:59.974 2497-2497/? I/WearableService: Wearable Services stopping

                                              [ 04-03 20:26:59.976   402:  402 W/         ]
                                              debuggerd: handling request: pid=29708 uid=10171 gid=10171 tid=29747
04-03 20:27:00.017 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.025 1600-1600/? I/EventCenter: EventCenter Get :android.intent.action.TIME_TICK
04-03 20:27:00.032 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.039 1600-1600/? E/DateLunarView: mDateString is: mar 3 avr
04-03 20:27:00.042 1600-1600/? E/DateLunarView: mDateString is: mar 3 avr
04-03 20:27:00.054 2572-2572/? I/HwLauncher: Model  onReceive intent=Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }
04-03 20:27:00.054 2572-2572/? I/HwLauncher: Model  onReceive user=UserHandle{0}
04-03 20:27:00.079 29868-29868/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-03 20:27:00.079 29868-29868/? A/DEBUG: Build fingerprint: 'HUAWEI/PRA-LX1/HWPRA-H:7.0/HUAWEIPRA-LX1/C432B196:user/release-keys'
04-03 20:27:00.079 29868-29868/? A/DEBUG: Revision: '0'
04-03 20:27:00.079 29868-29868/? A/DEBUG: ABI: 'arm64'
04-03 20:27:00.079 29868-29868/? A/DEBUG: pid: 29708, tid: 29747, name: GLThread 3385  >>> com.mygdx.game <<<
04-03 20:27:00.079 29868-29868/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7a9a07b400
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x0   0000007a9a07b400  x1   00000000000000b8  x2   0000007899b36980  x3   0000000000000002
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x4   0000000000000001  x5   0000000000000001  x6   0000000000000000  x7   0000000000000000
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x8   000000789775e098  x9   0000000000000000  x10  0000000000000001  x11  0000000000000001
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x12  000000789aa1a7e8  x13  000000789aa1a884  x14  00000078b7ab1150  x15  0000000000000060
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x16  000000789775da18  x17  000000789772f9d8  x18  0000000000000001  x19  0000007899b36980
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x20  00000078b687a270  x21  0000007899b369c0  x22  0000000000000006  x23  00000078b6a13fa0
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x24  0000000000000048  x25  604eae760b11fb4a  x26  00000078a908ca98  x27  00000078a908ca00
04-03 20:27:00.079 29868-29868/? A/DEBUG:     x28  000000789aa1a880  x29  000000789aa1a7a0  x30  0000007897733004
04-03 20:27:00.079 29868-29868/? A/DEBUG:     sp   000000789aa1a770  pc   000000789772fa34  pstate 0000000080000000
04-03 20:27:00.087 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.089 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.092 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.094 1600-1600/? W/ExpandableNotificationRow: setActionsBackground,null == view,mPublicLayout
04-03 20:27:00.097 1600-1600/? W/HwKeyguardDragHelper: AnimationBlocked
04-03 20:27:00.098 29868-29868/? A/DEBUG: backtrace:
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #00 pc 000000000001ba34  /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (_ZN16b2BlockAllocator8AllocateEi+92)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #01 pc 000000000001f000  /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (_ZN7b2World10CreateBodyEPK9b2BodyDef+48)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #02 pc 000000000002f6d0  /data/app/com.mygdx.game-2/lib/arm64/libgdx-box2d.so (Java_com_badlogic_gdx_physics_box2d_World_jniCreateBody+160)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #03 pc 00000000000db790  /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #04 pc 00000000000d21b4  /system/lib64/libart.so (art_quick_invoke_stub+580)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #05 pc 00000000000dee80  /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+204)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #06 pc 000000000028cbf0  /system/lib64/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+312)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #07 pc 0000000000286cac  /system/lib64/libart.so (_ZN3art11interpreter6DoCallILb1ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+444)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #08 pc 00000000005556e4  /system/lib64/libart.so (MterpInvokeDirectRange+384)
04-03 20:27:00.098 29868-29868/? A/DEBUG:     #09 pc 00000000000c4f94  /system/lib64/libart.so (ExecuteMterpImpl+15252)
04-03 20:27:00.123 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
04-03 20:27:00.131 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null
04-03 20:27:00.136 2572-2572/? E/HW-JPEG-DEC: [HME_JPEG_DEC_Delete](3321): HME_JPEG_DEC_Delete: decoder_ctx=null


                                          [ 04-03 20:27:00.390   402:  402 W/         ]
                                          debuggerd: resuming target 29708

EDIT2:我请了两个朋友来测试这个应用程序。第一个有一个oneplus 3t,它不会崩溃。另一个有一个华为 Mate 9,它崩溃了。

【问题讨论】:

  • 请将您的设备连接到计算机以查看崩溃时的logcat 错误并在此处发布。
  • 我已经在我的帖子中编辑了 logcat :)
  • 你能不能在破坏身体的循环之前调用更新方法,看看会发生什么。
  • 我在我的问题中提到了更新方法 :) 我在更新和 CreateEnemy() 之后放置了 for 循环。我已将日志放在问题的末尾:) 顺便说一下,如果条件为真,更新方法只会创建一个子弹(水)。

标签: java android android-studio libgdx segmentation-fault


【解决方案1】:

这肯定是 box2d 分配问题,而不是电话/制造特定问题。你可以做的是在你销毁它时将body对象设置为null,你会看到发生了什么。

试试这个:

for (int i = 0; i < remove.size(); i++) {
    world.destroyBody(remove.get(i));
    remove.get(i) = null;

    /*for (int n = 0; i < y.getJointList().size; n++){
        world.destroyJoint(y.getJointList().get(n).joint);
    }*/
}

remove.clear();

【讨论】:

  • 感谢您的回答,但我不允许这样做 remove.get(i)=null;所以我只尝试了 remove.clear();但它仍然不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-02
  • 2015-12-06
  • 2013-11-24
  • 1970-01-01
  • 1970-01-01
  • 2020-04-23
相关资源
最近更新 更多