-2

Right I have 5 views. One of the views is called RecordViewController. (RecordViewController is causing the error) I can switch through views fine. But once I get onto the recordviewcontroller, I can switch to another view. But if I want to switch back to recordviewcontroller. It throws me out of my app and gives me this error:

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.)

Here is the code for recordviewcontroller - Ive removed the switching view code, as its not needed.

@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
Zoe
  • 27,060
  • 21
  • 118
  • 148
LA12
  • 271
  • 1
  • 4
  • 7
  • 1
    Try [enabling zombies](http://stackoverflow.com/questions/2190227/how-do-i-set-nszombieenabled-in-xcode-4)... – jtbandes Aug 26 '11 at 23:33
  • 1
    your code would be much easier to read, if you would have a nicer formatting (less blank lines, no comments for the templates) – vikingosegundo Aug 27 '11 at 03:25

3 Answers3

0

Sounds like you are not retaining your recordViewController, so when you push another view, it's released, and when you try to go back, it's not there anymore.

If you are not using ARC, retain it when you create it.

EmilioPelaez
  • 18,758
  • 6
  • 46
  • 50
0

Remove the implementations of the following methods altogether:

+ (id)allocWithZone:(NSZone*)zone 

- (id)copyWithZone:(NSZone *)zone 

- (id)retain 

- (NSUInteger)retainCount 

- (void)release

And change the implementation of sharedInstance to the following and also add the implementation of alloc shown below.

+(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;
}
gamozzii
  • 3,911
  • 1
  • 30
  • 34
  • Hi I get this error. *** Assertion failure in +[RecordViewController alloc],Classes/RecordViewController.m:111 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to allocated second singleton RecordViewController' *** Call stack at first throw: – LA12 Aug 27 '11 at 18:38
0

I had this issue several times, and it was always some sort of infinitive recursion — most likely be calling the setter from with-in the setter.

edit
googleling for it I found this: ERROR: Memory Leak, data formatters temporarily unavailable

As your code also is leaking, it could be the same problem.

Community
  • 1
  • 1
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178