Microphone usage bug in VisionOS - showstopper

Ran into this in a more elaborate setup, reproduced with a minimal example:

    void Start()
        AudioSource audioSource = GetComponent<AudioSource>();
        audioSource.clip = Microphone.Start("", true, 10, 44100);

Will work on the build / install, then fail on every subsequent run and/or app update. Once uninstalled and reinstalled, permissions have to be given again, then it works once. Any further re-runs or app updates fail with the following generic error:

           AURemoteIO.cpp:1702  AUIOClient_StartIO failed (561145187)
Starting microphone failed: "An error occured trying to initialize the recording device. " (70)

561145187 corresponds to AVAudioSessionErrorCodeCannotStartRecording, which notes:

This error type usually occurs when an app starts a mixable recording from the background and it isn’t configured as an Inter-App Audio app.

Maybe you’re trying to start the microphone too early, when the app is still starting up? Have you tried starting the microphone a frame later?

The reason why it works once could be related to the permission prompt, which delays the actual start of the recording session. Only when the permission is already granted is the session started immediately.

ah, good catch, thank you! I found that definition but didn’t have that intuition. Throwing a 2 second delay at it solves it most of the time, albeit not fully, which is interesting. I’ll keep debugging, but I think you nailed the root cause. Thank you!