iphone - 奇怪的 iOS 崩溃
<p><p>我仅在设备上的发布版本中发生了非常间歇性的崩溃。以下是崩溃日志的相关部分:</p>
<pre><code>Exception Type:EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000f
Crashed Thread:0
Thread 0 name:Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x357c6fbc objc_msgSend + 16
1 CoreFoundation 0x33ff9020 CFRetain + 76
2 GraphicsServices 0x35c45af2 GSFontCreateWithName + 178
3 UIKit 0x3514264c UINewFont + 52
4 UIKit 0x351425fc + + 12
5 MyApp 0x0002bc68 - (STDrawer.mm:284)
6 MyApp 0x0002b8e0 - (STDrawer.mm:179)
7 MyApp 0x0002b7e0 - (STDrawer.mm:146)
8 MyApp 0x0000fb72 - (STGameController.mm:940)
9 MyApp 0x00015b16 - (STGame.mm:218)
10MyApp 0x00018c0e - (STGameClient.mm:461)
11MyApp 0x00017520 - (STGameClient.mm:150)
12MyApp 0x0003a02c - (STLocalConnClient.mm:115)
13Foundation 0x31b7593c __NSFireDelayedPerform + 408
14CoreFoundation 0x34084a5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
15CoreFoundation 0x340846c2 __CFRunLoopDoTimer + 358
16CoreFoundation 0x34083298 __CFRunLoopRun + 1200
17CoreFoundation 0x340064d6 CFRunLoopRunSpecific + 294
18CoreFoundation 0x3400639e CFRunLoopRunInMode + 98
19GraphicsServices 0x35c46fc6 GSEventRunModal + 150
20UIKit 0x3514b73c UIApplicationMain + 1084
21MyApp 0x000031c8 main (main.mm:113)
22MyApp 0x00002e28 start + 32
</code></pre>
<p>这是缩短的代码:</p>
<pre><code>-(UIButton*)createButtonWithTitle: (NSString*)title backgroundColor: (UIColor*)backgroundColor
{
...
UIButton* button = [ initWithFrame: CGRectZero];
button.titleLabel.font = ;
button.titleLabel.adjustsFontSizeToFitWidth = YES;
;
button.backgroundColor = ;
...
return ;
}
</code></pre>
<p>我已经看到至少 4 次来自 <code>button.titleLabel.font</code> 行的崩溃和一个来自 <code>button.titleLabel.adjustsFontSizeToFitWidth</code> 的崩溃(后者与 <code>-[ CALayer pointSize]: 无法识别的选择器发送到实例</code>)。</p>
<p>我认为这是一个内存问题,所以我在模拟器下使用 Valgrind 运行了该应用程序,包括发布和调试版本,但没有任何结果。它在 Apple 的库中找到了一堆东西,但在我的代码中没有。并且在分配后立即发生崩溃。怎么会腐败这么快?</p>
<p>我不确定下一步该做什么。非常欢迎任何建议。</p>
<p>编辑:这是 <code>adjustsFontSizeToFitWidth</code> 的爆炸:</p>
<pre><code>Exception Type:EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:0
Last Exception Backtrace:
0 CoreFoundation 0x33a888bf __exceptionPreprocess + 163
1 libobjc.A.dylib 0x351a41e5 objc_exception_throw + 33
2 CoreFoundation 0x33a8bacb - + 175
3 CoreFoundation 0x33a8a945 ___forwarding___ + 301
4 CoreFoundation 0x339e5680 _CF_forwarding_prep_0 + 48
5 UIKit 0x34b84107 - + 279
6 MyApp 0x0003b7e4 - (STDrawer.mm:288)
7 MyApp 0x0003b4a0 - (STDrawer.mm:184)
8 MyApp 0x0003b364 - (STDrawer.mm:147)
9 MyApp 0x00014ba8 - (STGameController.mm:943)
10MyApp 0x0001c0bc - (STGame.mm:219)
11MyApp 0x0001fa98 - (STGameClient.mm:461)
12MyApp 0x000213b4 - (STGameClient.mm:151)
13MyApp 0x00050c7c - (STLocalConnClient.mm:116)
14Foundation 0x3154d943 __NSFireDelayedPerform + 415
15CoreFoundation 0x33a5ca63 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 15
16CoreFoundation 0x33a5c6c9 __CFRunLoopDoTimer + 365
17CoreFoundation 0x33a5b29f __CFRunLoopRun + 1207
18CoreFoundation 0x339de4dd CFRunLoopRunSpecific + 301
19CoreFoundation 0x339de3a5 CFRunLoopRunInMode + 105
20GraphicsServices 0x3561efcd GSEventRunModal + 157
21UIKit 0x34b23743 UIApplicationMain + 1091
22MyApp 0x000031f8 main (main.mm:121)
23MyApp 0x00002c90 start + 40
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我遇到了同样的问题,原来是我不小心</p>
<pre><code>;
</code></pre>
<p>使用 NSString 而不是 UIImage 设置图像</p></p>
<p style="font-size: 20px;">关于iphone - 奇怪的 iOS 崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/9318377/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/9318377/
</a>
</p>
页:
[1]