title: AVAudioEngine throws exception when connecting AVAudioPlayerNode to output
body: <p>All I want to do (for now) is play a sound file using <code>AVAudioEngine</code> and <code>AVAudioPlayerNode</code>. Here's my code:</p>
  
  <pre><code>//Init engine and player
  let audioEngine = AVAudioEngine()
  let audioPlayerNode = AVAudioPlayerNode()
  
  //Hook them up
  audioEngine.attach(audioPlayerNode)
  audioEngine.connect(audioPlayerNode, to: audioEngine.outputNode, format: nil) // &lt; error
  </code></pre>
  
  <p>While executing the last line, an exception is thrown. Nothing is printed to the console and the execution continues, but when I set an exceptional breakpoint I get the following with <a href="https://developer.apple.com/library/content/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-basics.html" rel="nofollow noreferrer">LLDB</a>:</p>
  
  <pre><code>(lldb) po [$arg1 reason]
  error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0xffffd593).
  The process has been returned to the state before expression evaluation.
  </code></pre>
  
  <p>What can't be accessed here? I haven't even loaded a file yet... Thanks for any hints.</p>
  
  <p><em>Environment</em></p>
  
  <ul>
  <li>Xcode 8.2.1</li>
  <li>iPhone 5 running on iOS 10.3.2 (14F89)</li>
  </ul>
  
  <p><strong>Edit</strong></p>
  
  <p>Here is some more contextual information. The code above is part of an iOS game built with <code>SpriteKit</code> and <code>GameplayKit</code>. It is located in a subclass of <code>GKStateMachine</code>, within a method called <code>playSound</code>. This method is invoked in course of a touch event originating from my subclassed <code>SKScene</code> called <code>GameScene</code>. Upon <code>touchesBegan</code>, the call is delegated to all entities with a <code>TouchComponent</code> that have a method with the same signature (<code>touchesBegan</code>). These components will fire a <code>touchDown</code> event to their delegate, which is in turn my subclass of <code>GKStateMachine</code> called <code>GameStateMachine</code>. If the touch event is <em>correct</em> w.r.t. the game rules, the <code>score</code> property of my <code>GameStateMachine</code> is incremented. Within the <code>score</code> setter, the final method <code>playSound</code> is called if the score increases. Here's a sequence diagram of what I just described:</p>
  
  <p><a href="https://i.stack.imgur.com/Buwm0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Buwm0.png" alt="Sequence Diagram showing how &quot;playSound&quot; is invoked"></a></p>