节目接收信号:“EXC_BAD_ACCESS”

Posted

技术标签:

【中文标题】节目接收信号:“EXC_BAD_ACCESS”【英文标题】:Program received signal: “EXC_BAD_ACCESS” 【发布时间】:2011-08-26 23:27:21 【问题描述】:

是的,我有 5 个视图。其中一个视图称为 RecordViewController。 (RecordViewController 导致错误) 我可以很好地切换视图。但是一旦我进入recordviewcontroller,我就可以切换到另一个视图。但是如果我想切换回recordviewcontroller。它把我扔出我的应用程序并给我这个错误:

Program received signal:  “EXC_BAD_ACCESS”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (The program being debugged was signaled while in a function called from GDB.
GDB has restored the context to what it was before the call.
To change this behavior use "set unwindonsignal off"
Evaluation of the expression containing the function (gdb_objc_startDebuggerMode) will be abandoned.)

这是 recordviewcontroller 的代码 - 我删除了切换视图代码,因为它不需要。

@implementation RecordViewController
@synthesize actSpinner, btnStart, btnPlay;



-(void)countUp 

    mainInt += 1;
    seconds.text = [NSString stringWithFormat:@"%02d", mainInt];





static RecordViewController *sharedInstance = nil;


+ (RecordViewController*)sharedInstance 
    if (sharedInstance == nil) 
        sharedInstance = [[super allocWithZone:NULL] init];
    

    return sharedInstance;



+ (id)allocWithZone:(NSZone*)zone 
    return [[self sharedInstance] retain];



- (id)copyWithZone:(NSZone *)zone 
    return self;



- (id)retain 
    return self;



- (NSUInteger)retainCount 
    return NSUIntegerMax;



- (void)release 




- (id)autorelease 
    return self;


- (void)viewDidLoad 
    [super viewDidLoad];


    toggle = YES;
    btnPlay.hidden = YES;


    AVAudiosession * audioSession = [AVAudioSession sharedInstance];

    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];

    [audioSession setActive:YES error: &error];







- (IBAction)  start_button_pressed


    if(toggle)
    
        toggle = NO;
        [actSpinner startAnimating];
        [btnStart setImage:[UIImage imageNamed:@"recordstop.png"] forState:UIControlStateNormal];
        mainInt = 0;
        theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countUp) userInfo:nil repeats:YES];


        btnPlay.enabled = toggle;
        btnPlay.hidden = !toggle;


        NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
        [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
        [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
        [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

        recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"%.0f.%@", [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"caf"]]];
        NSLog(@"Using File called: %@",recordedTmpFile);

        recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
        [recorder setDelegate:self];
        [recorder prepareToRecord];

        [recorder record];


    
    else
    
        toggle = YES;
        [actSpinner stopAnimating];
        [btnStart setImage:[UIImage imageNamed:@"recordrecord.png"] forState:UIControlStateNormal];
        btnPlay.enabled = toggle;
        btnPlay.hidden = !toggle;
        [theTimer invalidate];

        NSLog(@"Using File called: %@",recordedTmpFile);

        [recorder stop];
    


- (void)didReceiveMemoryWarning 
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.


-(IBAction) play_button_pressed


    AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
    [avPlayer prepareToPlay];
    [avPlayer play];



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);


- (void)viewDidUnload 
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    //Clean up the temp file.
    NSFileManager * fm = [NSFileManager defaultManager];
    [fm removeItemAtPath:[recordedTmpFile path] error:&error];
    //Call the dealloc on the remaining objects.
    [recorder dealloc];
    recorder = nil;
    recordedTmpFile = nil;


- (void)dealloc 
    [super dealloc];


@end

【问题讨论】:

试试enabling zombies... 你的代码会更容易阅读,如果你有更好的格式(更少的空白行,没有模板的 cmets) 【参考方案1】:

听起来你没有保留你的recordViewController,所以当你推送另一个视图时,它会被释放,当你尝试返回时,它不再存在了。

如果您不使用 ARC,请在创建时保留它。

【讨论】:

ARC没有被使用,我需要专门保留哪一部分? 如果您不使用 arc,那么您的代码中会包含很多对象。查看内存管理指南。【参考方案2】:

完全删除以下方法的实现:

+ (id)allocWithZone:(NSZone*)zone 

- (id)copyWithZone:(NSZone *)zone 

- (id)retain 

- (NSUInteger)retainCount 

- (void)release

将sharedInstance的实现改成如下,alloc的实现如下图所示。

+(RecordViewController *) sharedInstance 
@synchronized([RecordViewController class])

    if (!sharedInstance)
    
        [[self alloc]init];
    
    return sharedInstance;

return nil;


+(id) alloc

    @synchronized([RecordViewController class])
    
        NSAssert(sharedInstance == nil, @"Attempted to allocated second singleton  RecordViewController");
        sharedInstance = [super alloc];
        return sharedInstance;
    
    return nil;

【讨论】:

您好,我收到此错误。 *** +[RecordViewController alloc],Classes/RecordViewController.m:111 中的断言失败 *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“尝试分配第二个单例 RecordViewController” *** 第一次抛出调用堆栈:【参考方案3】:

我多次遇到这个问题,而且总是某种不定式递归——很可能是从 setter 内部调用 setter。

编辑 谷歌搜索它我发现了这个:ERROR: Memory Leak, data formatters temporarily unavailable

由于您的代码也在泄漏,这可能是同样的问题。

【讨论】:

以上是关于节目接收信号:“EXC_BAD_ACCESS”的主要内容,如果未能解决你的问题,请参考以下文章

为啥我在字符串变量上得到“程序接收信号:”EXC_BAD_ACCESS“

程序接收信号:带有Core Data的“EXC_BAD_ACCESS”

这个错误对我的程序有啥影响? “EXC_BAD_ACCESS”。共享库

节目接收信号:“0”。数据格式化程序暂时不可用

卫星电视接收机。双模机和单模机有啥取别

卫星接收器参数是啥