简体   繁体   English

如果语句导致iOS设备崩溃,但不会导致模拟器崩溃

[英]If statement causes a crash in the iOS device but not in the Simulator

So, this code runs properly, without causing any crashes in the iOS simulator. 因此,此代码可以正常运行,而不会导致iOS模拟器崩溃。 However, on my iOS device (my iPhone), this causes a crash! 但是,在我的iOS设备(我的iPhone)上,这会导致崩溃! Can anyone guess why? 谁能猜到为什么? The logs haven't helped anywhere. 日志对任何地方都没有帮助。

NSInteger loops = 1;
char character = '.';
if ([futureTr rangeOfString:[NSString stringWithFormat:@"%c",character]].location != NSNotFound) {
    NSArray *dotsArray = [futureTr componentsSeparatedByString:[NSString stringWithFormat:@"%c",character]];
    loops = [dotsArray count];
    if ([[dotsArray objectAtIndex:loops-1] isEqualToString:@""] || [dotsArray objectAtIndex:loops-1] == nil) {
        loops--;
    }
}

And I know that it's this statement that causes trouble, because I comment it out and the app just works fine! 而且我知道,这是引起麻烦的语句,因为我将其注释掉,并且该应用程序正常运行! What can be going on? 怎么回事?

Based on the discussion in the comments, the problem is that futureTr is being released at some point and this code then attempts to use the now deallocated pointer resulting in the "BAD_ACCESS" exception. 根据注释中的讨论,问题在于, futureTr在某个时候被释放,然后此代码尝试使用现在释放的指针,从而导致“ BAD_ACCESS”异常。

Proper memory management of this variable will alleviate the problem. 对此变量进行适当的内存管理将缓解此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 fprintf 导致设备崩溃但不是模拟器? - fprintf causes device to crash but not simulator? 添加Crashlytics SDK会导致设备崩溃,但不会导致模拟器崩溃 - Adding Crashlytics SDK causes crash on device but not on simulator AVPlayer导致模拟器崩溃,但在设备上运行正常 - AVPlayer causes Simulator to crash but runs fine on device viewWillDisappear导致应用在设备上崩溃,但在模拟器上不崩溃 - viewWillDisappear Causes App to Crash on Device but not on Simulator RTCPeerConnectionFactory.peerConnectionWithConfiguration导致IOS模拟器崩溃 - RTCPeerConnectionFactory.peerConnectionWithConfiguration causes IOS simulator crash 应用程序在设备上崩溃但在模拟器 iOS 上工作 - App crash on device but works on simulator iOS iOS Firebase-模拟器崩溃,但设备不持久 - iOS Firebase - Crash in simulator but not device w/ persistence Xcode 5和iOS 7模拟器/设备崩溃并出现僵尸错误-适用于iOS6 - Xcode 5 and iOS 7 Simulator/Device Crash with zombie error - Works on iOS6 UICollectionView-iOS 10-在iPhone 6 Plus模拟器上崩溃但可在真实设备上运行 - UICollectionView - iOS 10 - crash on iPhone 6 Plus simulator but works on real device Flutter 应用程序在启动时崩溃(仅 IOS,模拟器和真机都有) - Flutter app crash on startup (only IOS, both simulator and real device)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM