[iosoc] UIWebView 首次非主线程调用导致crash

xiaoxiao2021-02-27  284

记录最近遇到的一个奇葩的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)
转载请注明原文地址: https://www.6miu.com/read-2411.html

最新回复(0)