Note that there are some explanatory texts on larger screens.

plurals
  1. PORelease AVAudioPlayer in iOS4/iOS5 giving EXC_BAD_ACCESS error
    primarykey
    data
    text
    <p><strong>EDIT</strong>: Updated my device (and deployment target) from iOS 4.3.5 to iOS 5.1.1 and still has the same issue</p> <p>Having a problem releasing a class member <strong>AVAudioPlayer</strong> to play another sound after playing a sound.</p> <p>This only seems to be a problem on one of my devices, a <strong>3rd</strong> generation <strong>iPod Touch</strong> running <strong>iOS 4.3.5/5.1.1</strong>.</p> <p>My <strong>4th</strong> and <strong>5th</strong> generation devices running <strong>iOS 6</strong> run just fine.</p> <pre><code>[audio release]; audio = nil; @try { audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&amp;error]; if ((audio != nil) &amp;&amp; (!error)) { audio.delegate = (id)self; audio.volume = gVolume/10; [audio play]; } else { [audio release]; audio = nil; } } @catch (NSException *exception) { [audio release]; audio = nil; } </code></pre> <p>First time through it plays just fine, but when this code executes a second time to play another sound, it gives an <strong>EXC_BAD_ACCESS</strong> error, which does not happen on my <strong>4th/5th</strong> generation devices.</p> <p>I purposely delay the <strong>release</strong> until I need to play another sound in order to give the <strong>play</strong> time to perform.</p> <p>Tried working with <strong>AVAudioPlayerDelegate</strong> but that didn't solve the problem, nor does calling:</p> <pre><code>[audio prepareToPlay]; </code></pre> <p>I do initialize <strong>audio</strong> to <strong>nil</strong> in <strong>viewDidLoad</strong>, and clean up in <strong>viewDidUnload</strong> and <strong>dealloc</strong>.</p> <p>Was having a lot of memory leak issues but this version of the code seemed to have solved that.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload