[ios/oc] UIWebView 首次非主线程调用导致crash

记录最近遇到的一个奇葩的crash:

现象:

UIWebView在首次被调用,如

[UIWebView class]

时,如果在非主线程,会导致crash。

原因:

UIWebView使用了类似懒加载的机制,第一次调用时会进行部分初始化,该部分初始化需要在主线程进行。

解决方案:

在主线程调用一把[UIWebView class],之后就可以在任意线程进行UIWebView相关操作了。

po时抛出的错误:

error: Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0).
The process has been returned to the state before expression evaluation.

crash堆栈

WebCore`WebCore::FloatingPointEnvironment::saveMainThreadEnvironment:
    0x121f623d0 <+0>:  pushq  %rbp
    0x121f623d1 <+1>:  movq   %rsp, %rbp
    0x121f623d4 <+4>:  pushq  %rbx
    0x121f623d5 <+5>:  pushq  %rax
    0x121f623d6 <+6>:  movq   %rdi, %rbx
    0x121f623d9 <+9>:  cmpb   $0x0, 0x10(%rbx)
    0x121f623dd <+13>: jne    0x121f623fb               ; <+43>
    0x121f623df <+15>: callq  0x122df09b0               ; symbol stub for: WTF::isUIThread()
    0x121f623e4 <+20>: testb  %al, %al
    0x121f623e6 <+22>: je     0x121f623fc               ; <+44>
    0x121f623e8 <+24>: movq   %rbx, %rdi
    0x121f623eb <+27>: callq  0x122df1a12               ; symbol stub for: fegetenv
    0x121f623f0 <+32>: movb   $0x1, 0x10(%rbx)
    0x121f623f4 <+36>: addq   $0x8, %rsp
    0x121f623f8 <+40>: popq   %rbx
    0x121f623f9 <+41>: popq   %rbp
    0x121f623fa <+42>: retq   
    0x121f623fb <+43>: int3   
    0x121f623fc <+44>: int3   
->  0x121f623fd <+45>: nopl   (%rax)
WebCore`WebCore::FloatPoint::FloatPoint:
    0x121f62430 <+0>:  pushq  %rbp
    0x121f62431 <+1>:  movq   %rsp, %rbp
->  0x121f62434 <+4>:  cvtsi2ssl (%rsi), %xmm0
    0x121f62438 <+8>:  movss  %xmm0, (%rdi)
    0x121f6243c <+12>: xorps  %xmm0, %xmm0
    0x121f6243f <+15>: cvtsi2ssl 0x4(%rsi), %xmm0
    0x121f62444 <+20>: movss  %xmm0, 0x4(%rdi)
    0x121f62449 <+25>: popq   %rbp
    0x121f6244a <+26>: retq   
    0x121f6244b <+27>: nopl   (%rax,%rax)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值