gpt4 book ai didi

java - Android Libgdx - 真实设备上出现 Sigsegv 11 错误,但模拟器上没有崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:29 44 4
gpt4 key购买 nike

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

该应用程序在 android studio 的模拟器上运行良好,但当我使用 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;
}

代码注释:水是射杀敌人的子弹。删除的是数组列表。

这是我的 act 方法的代码,它销毁要销毁的主体数组列表内的主体(碰撞方法,但要销毁到数组列表中的主体)。 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 没有摧毁尸体,应用程序就不会崩溃。所以我知道销毁函数会使应用程序崩溃。

这是 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 的菜鸟,请帮忙<3(很抱歉我的英语不好!)

编辑:要回答“Subrata M”评论中的问题,如果我将 destroy 方法放在更新和 createEnemy() 之后,这里是 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:我请两个 friend 测试该应用程序。第一个有oneplus 3t,它不会崩溃。另一个有华为 Mate 9,但它崩溃了。

最佳答案

这肯定是 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();

关于java - Android Libgdx - 真实设备上出现 Sigsegv 11 错误,但模拟器上没有崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49634652/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com