title: Android Libgdx - Sigsegv 11 error on real device but no crash on emulator
body: <p>I am currently trying to make an application with libgdx on android.</p>
  
  <p>The application is working fine on emulator of android studio but there is a crash with my real phone when I do a world.destroy(body) with the library box2d.
  More precisely, during the execution of the game, the application destroys 2 bodys after a collision like it is suppose to do but after 1 sec the app crash.</p>
  
  <p>Here is the code of my listener of collision.</p>
  
  <pre><code>@Override
  public void beginContact(Contact contact) {
  
      Body a = contact.getFixtureA().getBody();
      Body b = contact.getFixtureB().getBody();
  
      if ((BodyUtils.bodyIsWater(b) &amp;&amp; BodyUtils.bodyIsEnemy(a))|| (BodyUtils.bodyIsEnemy(b) &amp;&amp; BodyUtils.bodyIsWater(a))){
              if (!remove.contains(a)) {
                  remove.add(a);
              }
              if (!remove.contains(b)) {
                  remove.add(b);
              }
              iswater = false;
      }
      else if(BodyUtils.bodyIsGround(b) &amp;&amp; BodyUtils.bodyIsWater(a)){
          if(!remove.contains(a)) {
              remove.add(a);
          }
          iswater=false;
      }
      else if(BodyUtils.bodyIsGround(a) &amp;&amp; BodyUtils.bodyIsWater(b)){
          if(!remove.contains(b)) {
              remove.add(b);
          }
          iswater=false;
      }
      a=null;
      b=null;
  }
  </code></pre>
  
  <p>Comment about the code: Water is the bullet which shoot the ennemy. Remove is the arraylist.</p>
  
  <p>Here is the code of my act method which destroy the body that are inside my arraylist of body to destroy ( the collision method but body to destroy into the arraylist ). The destroy call is into the for loop.</p>
  
  <pre><code>@Override
  public void act(float delta) {
      super.act(delta);
  
      // Fixed timestep
      accumulator += delta;
  
      while (accumulator &gt;= delta) {
          world.step(TIME_STEP, 10, 10);
          accumulator -= TIME_STEP;
      }
  
      for (int i = 0; i &lt; remove.size(); i++) {
          world.destroyBody(remove.get(i));
          remove.remove(i);
          /*for (int n = 0; i &lt; y.getJointList().size; n++){
              world.destroyJoint(y.getJointList().get(n).joint);
          }*/
      }
  
      if(add%100==0 &amp;&amp; !iswater) {
          Array&lt;Body&gt; bodies = new Array&lt;Body&gt;(world.getBodyCount());
          world.getBodies(bodies);
  
          for (Body body : bodies) {
              update(body);
          }
      }
      if(add%80==0){
          createEnemy();
      }
  
      add++;
  
  }
  </code></pre>
  
  <p>Here is the content of the update methode :</p>
  
  <pre><code>private void update(Body body) {
      if (BodyUtils.bodyIsEnemy(body) &amp;&amp; !iswater) {
          EnemyUserData z = (EnemyUserData) body.getUserData();
          Vector2 m=body.getPosition();
          if(m.x&lt;23f){
              createWater(z,m);
              iswater=true;
          }
      }
  }
  </code></pre>
  
  <p>First, I tried to figure out where to problem was from and I found that the app was not crashing if a wasn't destroying bodies. So know I know that the destroy function makes the app crash.</p>
  
  <p>Here is the Sigsegv log:</p>
  
  <pre><code>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  &gt;&gt;&gt; com.mygdx.game &lt;&lt;&lt;
  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
  </code></pre>
  
  <p>I've also tested an emulator which have the same android version of my phone and it worked. ( it is version 7 api 24 ). So it isn't the problem.</p>
  
  <p>ps: I don't destroy twice a body (I've put some condition to avoid it).</p>
  
  <p>I am a noob of libgdx please help &lt;3 (and sorry for my bad english!)</p>
  
  <p>EDIT : To answers a question in the comment of  "Subrata M" here is the logcat if i put the destroy method after the update and the createEnemy().</p>
  
  <pre><code>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  &gt;&gt;&gt; com.mygdx.game &lt;&lt;&lt;
  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
  </code></pre>
  
  <p>EDIT2 : I asked two friends to test the app. the first has got a oneplus 3t and it doesn't crash. The other has got a Huawei Mate 9 and it crash.</p>