简体   繁体   中英

iOS throws EXC_BAD_ACCESS error and crashes

I am trying to develop a game with SpriteKit using swift. The game randomly throws this error and the app crashes. I don't know which exactly code causes the crash as I am new to game development.

Error:

EXC_BAD_ACCESS (code=EXC_l386_GPFLT)

Here is the thread 1 UIApplicationMain

    0x10e899d86 <+837>:  movq   %rbx, %rdx
    0x10e899d89 <+840>:  movq   %rax, %rcx
    0x10e899d8c <+843>:  movl   $0x990, %r8d
    0x10e899d92 <+849>:  xorb   %al, %al
    0x10e899d94 <+851>:  callq  *%r12
    0x10e899d97 <+854>:  movq   0xb59bba(%rip), %rsi      ; "class"
    0x10e899d9e <+861>:  movq   0xb7f57b(%rip), %rdi      ; (void *)0x000000010f41df18: UIApplication
    0x10e899da5 <+868>:  callq  *%r12
    0x10e899da8 <+871>:  movq   0xb5aa89(%rip), %rsi      ; "isSubclassOfClass:"
    0x10e899daf <+878>:  movq   %r14, %rdi
    0x10e899db2 <+881>:  movq   %rax, %rdx
    0x10e899db5 <+884>:  callq  *%r12
    0x10e899db8 <+887>:  movq   0xbecb39(%rip), %rbx      ; UIApp
    0x10e899dbf <+894>:  testb  %al, %al
    0x10e899dc1 <+896>:  je     0x10e899dd8               ; <+919>
    0x10e899dc3 <+898>:  movq   0xb59c86(%rip), %rsi      ; "setDelegate:"
    0x10e899dca <+905>:  movq   %rbx, %rdi
    0x10e899dcd <+908>:  movq   %rbx, %rdx
    0x10e899dd0 <+911>:  callq  *0x9b10e2(%rip)           ; (void *)0x000000010ddc7fc0: objc_msgSend
    0x10e899dd6 <+917>:  jmp    0x10e899e14               ; <+979>
    0x10e899dd8 <+919>:  movq   0xb59bd9(%rip), %rsi      ; "alloc"
    0x10e899ddf <+926>:  movq   %r14, %rdi
    0x10e899de2 <+929>:  callq  *%r12
    0x10e899de5 <+932>:  movq   0xb59dd4(%rip), %rsi      ; "init"
    0x10e899dec <+939>:  movq   %rax, %rdi
    0x10e899def <+942>:  callq  *%r12
    0x10e899df2 <+945>:  movq   0xb59e8f(%rip), %rsi      ; "autorelease"
    0x10e899df9 <+952>:  movq   %rax, %rdi
    0x10e899dfc <+955>:  callq  *%r12
    0x10e899dff <+958>:  movq   0xb5aa3a(%rip), %rsi      ; "_setDelegate:assumeOwnership:"
    0x10e899e06 <+965>:  movq   %rbx, %rdi
    0x10e899e09 <+968>:  movq   %rax, %rdx
    0x10e899e0c <+971>:  movl   $0x1, %ecx
    0x10e899e11 <+976>:  callq  *%r12
    0x10e899e14 <+979>:  movq   0xb59a95(%rip), %rsi      ; "release"
    0x10e899e1b <+986>:  movq   -0x30(%rbp), %rdi
    0x10e899e1f <+990>:  callq  *%r12
    0x10e899e22 <+993>:  movq   0xb5aa1f(%rip), %rsi      ; "_run"
    0x10e899e29 <+1000>: movq   0xbecac8(%rip), %rdi      ; UIApp
    0x10e899e30 <+1007>: callq  *%r12
->  0x10e899e33 <+1010>: xorl   %eax, %eax // ERROR LINE HERE
    0x10e899e35 <+1012>: addq   $0x28, %rsp
    0x10e899e39 <+1016>: popq   %rbx
    0x10e899e3a <+1017>: popq   %r12
    0x10e899e3c <+1019>: popq   %r13
    0x10e899e3e <+1021>: popq   %r14
    0x10e899e40 <+1023>: popq   %r15
    0x10e899e42 <+1025>: popq   %rbp
    0x10e899e43 <+1026>: retq   

Here is 0 objc_msgSend

libobjc.A.dylib`objc_msgSend:
    0x10ddc7fc0 <+0>:   testq  %rdi, %rdi
    0x10ddc7fc3 <+3>:   jle    0x10ddc8028               ; <+104>
    0x10ddc7fc5 <+5>:   movq   (%rdi), %r11
    0x10ddc7fc8 <+8>:   movq   %rsi, %r10
->  0x10ddc7fcb <+11>:  andl   0x18(%r11), %r10d
    0x10ddc7fcf <+15>:  shlq   $0x4, %r10
    0x10ddc7fd3 <+19>:  addq   0x10(%r11), %r10
    0x10ddc7fd7 <+23>:  cmpq   (%r10), %rsi
    0x10ddc7fda <+26>:  jne    0x10ddc7fe0               ; <+32>
    0x10ddc7fdc <+28>:  jmpq   *0x8(%r10)
    0x10ddc7fe0 <+32>:  cmpq   $0x0, (%r10)
    0x10ddc7fe4 <+36>:  je     0x10ddc8049               ; <+137>
    0x10ddc7fe6 <+38>:  cmpq   0x10(%r11), %r10
    0x10ddc7fea <+42>:  je     0x10ddc7ff9               ; <+57>
    0x10ddc7fec <+44>:  subq   $0x10, %r10
    0x10ddc7ff0 <+48>:  cmpq   (%r10), %rsi
    0x10ddc7ff3 <+51>:  jne    0x10ddc7fe0               ; <+32>
    0x10ddc7ff5 <+53>:  jmpq   *0x8(%r10)
    0x10ddc7ff9 <+57>:  movl   0x18(%r11), %r10d
    0x10ddc7ffd <+61>:  shlq   $0x4, %r10
    0x10ddc8001 <+65>:  addq   0x10(%r11), %r10
    0x10ddc8005 <+69>:  jmp    0x10ddc8017               ; <+87>
    0x10ddc8007 <+71>:  cmpq   $0x0, (%r10)
    0x10ddc800b <+75>:  je     0x10ddc8049               ; <+137>
    0x10ddc800d <+77>:  cmpq   0x10(%r11), %r10
    0x10ddc8011 <+81>:  je     0x10ddc8020               ; <+96>
    0x10ddc8013 <+83>:  subq   $0x10, %r10
    0x10ddc8017 <+87>:  cmpq   (%r10), %rsi
    0x10ddc801a <+90>:  jne    0x10ddc8007               ; <+71>
    0x10ddc801c <+92>:  jmpq   *0x8(%r10)
    0x10ddc8020 <+96>:  movq   %r11, %rdx
    0x10ddc8023 <+99>:  jmp    0x10ddb2771               ; objc_msgSend_corrupt_cache_error
    0x10ddc8028 <+104>: je     0x10ddc803e               ; <+126>
    0x10ddc802a <+106>: leaq   0x195fd7(%rip), %r11      ; objc_debug_taggedpointer_classes
    0x10ddc8031 <+113>: movq   %rdi, %r10
    0x10ddc8034 <+116>: shrq   $0x3c, %r10
    0x10ddc8038 <+120>: movq   (%r11,%r10,8), %r11
    0x10ddc803c <+124>: jmp    0x10ddc7fc8               ; <+8>
    0x10ddc803e <+126>: xorl   %eax, %eax
    0x10ddc8040 <+128>: xorl   %edx, %edx
    0x10ddc8042 <+130>: xorps  %xmm0, %xmm0
    0x10ddc8045 <+133>: xorps  %xmm1, %xmm1
    0x10ddc8048 <+136>: retq   
    0x10ddc8049 <+137>: enter  $0x88, $0x0
    0x10ddc804d <+141>: movdqa %xmm0, -0x80(%rbp)
    0x10ddc8052 <+146>: pushq  %rax
    0x10ddc8053 <+147>: movdqa %xmm1, -0x70(%rbp)
    0x10ddc8058 <+152>: pushq  %rdi
    0x10ddc8059 <+153>: movdqa %xmm2, -0x60(%rbp)
    0x10ddc805e <+158>: pushq  %rsi
    0x10ddc805f <+159>: movdqa %xmm3, -0x50(%rbp)
    0x10ddc8064 <+164>: pushq  %rdx
    0x10ddc8065 <+165>: movdqa %xmm4, -0x40(%rbp)
    0x10ddc806a <+170>: pushq  %rcx
    0x10ddc806b <+171>: movdqa %xmm5, -0x30(%rbp)
    0x10ddc8070 <+176>: pushq  %r8
    0x10ddc8072 <+178>: movdqa %xmm6, -0x20(%rbp)
    0x10ddc8077 <+183>: pushq  %r9
    0x10ddc8079 <+185>: movdqa %xmm7, -0x10(%rbp)
    0x10ddc807e <+190>: movq   %rdi, %rdi
    0x10ddc8081 <+193>: movq   %rsi, %rsi
    0x10ddc8084 <+196>: movq   %r11, %rdx
    0x10ddc8087 <+199>: callq  0x10ddbc469               ; _class_lookupMethodAndLoadCache3
    0x10ddc808c <+204>: movq   %rax, %r11
    0x10ddc808f <+207>: movdqa -0x80(%rbp), %xmm0
    0x10ddc8094 <+212>: popq   %r9
    0x10ddc8096 <+214>: movdqa -0x70(%rbp), %xmm1
    0x10ddc809b <+219>: popq   %r8
    0x10ddc809d <+221>: movdqa -0x60(%rbp), %xmm2
    0x10ddc80a2 <+226>: popq   %rcx
    0x10ddc80a3 <+227>: movdqa -0x50(%rbp), %xmm3
    0x10ddc80a8 <+232>: popq   %rdx
    0x10ddc80a9 <+233>: movdqa -0x40(%rbp), %xmm4
    0x10ddc80ae <+238>: popq   %rsi
    0x10ddc80af <+239>: movdqa -0x30(%rbp), %xmm5
    0x10ddc80b4 <+244>: popq   %rdi
    0x10ddc80b5 <+245>: movdqa -0x20(%rbp), %xmm6
    0x10ddc80ba <+250>: popq   %rax
    0x10ddc80bb <+251>: movdqa -0x10(%rbp), %xmm7
    0x10ddc80c0 <+256>: leave  
    0x10ddc80c1 <+257>: cmpq   %r11, %r11
    0x10ddc80c4 <+260>: jmpq   *%r11
    0x10ddc80c7 <+263>: nopw   %cs:(%rax,%rax)
    0x10ddc80d6 <+278>: nop    
    0x10ddc80d7 <+279>: nop    
    0x10ddc80d8 <+280>: nop    
    0x10ddc80d9 <+281>: nop    
    0x10ddc80da <+282>: nop    

How can I fix this error and stop the app from crashing?

Hope that you are familiar with the usages of break point in Xcode. Add an All Exception Break Point to see what is happening in side. You will find a good tutorial on Break Point over here .

添加所有异常断点

If you active the console (View -> Debug Area -> Activate Console, or Command + Shift + C) you can see a more detailed report of your crash. If you scroll back up when the app crashes you can see the reason.

To make things more clear I make one of my apps crash on purpose to make a screenshot for you. It shows the reason of the crash below.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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