PDA

View Full Version : CoreAudio and threads


Dan Potter
2005.03.19, 10:00 PM
I'm having an interesting issue in my game toolkit with CoreAudio and (I think) threading.

My basic setup goes something like this:
- NIB contains a window with an NSView
- Controller class links up with that and creates a GL context and such
- Start a second thread to run with the main game thread, while the "main" thread just answers messages

I know a lot of people think that's a bad idea ;) but honestly I don't have a lot of choice due to the fact that I built this toolkit to port some older games from the Dreamcast (which has a great deal of thread freedom :)).

Anyway, to get back to the point: In my "second thread" I'm creating CoreAudio units to stream audio out from OggVorbis. This all works fine. But sometimes when I call AudioOutputUnitStop(), I get a crash inside a CoreAudio thread, in its MixerDispatch. I'm making all AudioUnit calls from the same thread (create, start, stop, destroy). The crash doesn't make a ton of sense either, as the instruction it stops on (with the register values it stops with) doesn't look problematic.

I have heard some hints from Apple lists that using the CoreAudio functions on a thread that's not the main thread can cause issues (with destroy anyway). If that's the case.. that's going to be a big problem.

Anyone else see anything like this?

Dan Potter
2005.03.27, 11:55 PM
To answer my own question, it turns out the problem I was seeing was because I was destroying SoundManager channels before stopping them. So caveat emptor if you're still using that creaky old API...