异常信号停止

Posted

技术标签:

【中文标题】异常信号停止【英文标题】:Exception SIGSTOP 【发布时间】:2012-09-18 10:53:03 【问题描述】:

我是 XCode 和 Objective-C 的新手。当我让应用程序在模拟器中运行时,我弹出了这个异常。在 iPad 上它工作正常。分配 AVaudioPlayer 后,我会停止并发出警告 SIGSTOP。

有人有什么建议吗?这是一个严重的例外吗?提前致谢!

我不知道在哪里可以找到“堆栈跟踪”,所以我将 RUN 调试器放到 gdb 中: 来自这里的信息: 挂起的断点 1 - ""soundScape.m":112" 已解决 rndmitem 金额 网址

SIGSTOP 之前的行是: libc++abi.dylib`__cxa_throw: 0x46e4a44: pushl %ebp 0x46e4a45: movl %esp, %ebp

当前语言:自动;当前目标-c 0x1 似乎没有指向有效的对象。 0x2 似乎没有指向有效的对象。 文件://localhost/Users/myName/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/E92E5F03-0B07-4AF0-BFB4-E1F7009A4E78/babyschets.app/02Seawash.mp3 [切换到进程81163线程0x1720b] [切换到进程81163线程0x15803] 在异常状态寄存器下: trapno = (unsigned int) 0x000003 错误=(无符号整数)0x000000 faultvaddr = (unsigned int) 0x087df732 例如,当值如下时会发生这种情况:

随机项: (NSUInteger) $0 = 1 [没有可用的 Objective-C 描述]amountOfAudioFiles : (int) $1 = 2 [没有可用的 Objective-C 描述]url : (NSURL *) $2 = 0x07485860 file://localhost/Users/myName/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/E92E5F03-0B07-4AF0-BFB4-E1F7009A4E78/babyschets.app/02Seawash。 mp3

audioFiles1: (NSArray *) $4 = 0x0747d720 <__nsarrayi>( 01Seawash.mp3, 02海洗.mp3 )

int amountOfAudioFiles = [audioFiles1 count];
NSUInteger randomItem = arc4random()%(int)amountOfAudioFiles;

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:[NSString stringWithString:[audioFiles1 objectAtIndex:randomItem]]
                                     ofType:nil]];

NSError *error;

audioPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

好的,我已经清理了这段代码,这是我的解决方案。现在它像魅力一样运行:

在 .h 文件中: @property (nonatomic, 保留) AVAudioPlayer *audioPlayer1;

在 .m 文件中:

int amountOfAudioFiles = [audioFiles1 count];
int randomItem = (int)(arc4random()%amountOfAudioFiles);
if (randomItem < 0) randomItem = 0;

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:[NSString stringWithFormat:@"%@", [audioFiles1 objectAtIndex:randomItem]]
                                     ofType:nil]];


if (audioPlayer1) 
    if (audioPlayer1.isPlaying) 
        [audioPlayer1 stop];
        audioPlayer1 = nil;
    

 else 
    audioPlayer1 = [AVAudioPlayer alloc];


NSError *error;
audioPlayer1 = [audioPlayer1 initWithContentsOfURL:url error:NULL];

【问题讨论】:

当您的应用程序在 XCode 中崩溃时,通常调试器/控制台会向您显示包含错误详细信息的堆栈跟踪。有什么可以给我们看的吗? SIGSTOP 是一个不寻常的信号 - 通常用于终端中的作业控制(即Ctrl-Z 和后来的fg)! 【参考方案1】:

这意味着对象(在框架中)不存在于 ios 版本中。 也许您需要更新您测试/运行应用程序的 iOS 设备的 iOS。

【讨论】:

我的模拟器是5.1。这不是最新的吗? 在真正的 iOS 设备上尝试代码。最好使用 iOS 5.1.1,您的 AV 对象似乎会导致模拟器崩溃

以上是关于异常信号停止的主要内容,如果未能解决你的问题,请参考以下文章

iOS异常信号的捕获和简单处理

linux总结-第一讲-中断和异常

第十章 信号

unittest使用signal信号量

信号 goroutine 在通道关闭时停止

Linux C 捕捉终止信号以优雅终止