我有一段繪製曲線的代碼,並且在應用程序中至少有一年沒有任何問題。在過去的三天中,我突然收到了大約10份每日崩潰報告,全部來自iOS 7用戶。這些報告說,「for(int i = 1 etc」)這一行崩潰了,但我不能理解這個問題。崩潰日誌是指CoreGraphics,所以它可能是之前導致問題的行。驗證碼:簡單的CoreGraphics偶爾會畫圖崩潰,但只能在iOS 7上使用
CGContextBeginPath(cctx);
int step=220/lookupCount;
acx = 0;
acy = hf*100-bestResults[0]*hf*100/top;
CGContextMoveToPoint(cctx, acx, acy);
for(int i=1;i<lookupCount;i++){ //line 2005
acx = hf*i*step;
acy = hf*100-bestResults[i]*hf*100/top;
CGContextAddLineToPoint(cctx, acx , acy);
}
CGContextStrokePath(cctx);
和一塊崩潰日誌:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x395311fc ___pthread_kill + 8
1 libsystem_c.dylib 0x394e202d _abort + 77
2 libsystem_c.dylib 0x394c1c6b ___assert_rtn + 183
3 CoreGraphics 0x2ed0da09 CG::Path::is_empty() const + 1
4 racquetTune 0x000942d5 -[tension autoCorr] (tension.m:2005)
我一直在嘗試通過不同的變量設置爲零來重新創建崩潰或讓他們無限的,但任何「成功「有沒有人知道iOS7 CoreGraphics中可能導致這種情況的變化?
崩潰來自不同類型的硬件,代表少數用戶,但仍然過於頻繁而無法忽視。一個有趣的細節是,從iOS 7開始的兩天開始就沒有崩潰報告,但是之後有穩定的數據流。
事實證明,NaN的崩潰CGContextAddLineToPoint上iOS7,但不是5或6(我只測試一個INF數),所以這可能是原因。 – Sten
我可以在'CGContextMoveToPoint()'或'CGContextAddLineToPoint()'上使用[NaN](https://en.wikipedia.org/wiki/NaN#Floating_point)在iOS7/iOS8上重現相同的崩潰。要測試,請使用['NAN'](http://stackoverflow.com/q/16691207/1402846)。要解決該問題,請使用['isnan()'](http://stackoverflow.com/q/16691207/1402846)。 – Pang