diff --git a/libs/unity/library/Runtime/Scripts/Media/MicrophoneSource.cs b/libs/unity/library/Runtime/Scripts/Media/MicrophoneSource.cs index 079b8ac77..d9af642d7 100644 --- a/libs/unity/library/Runtime/Scripts/Media/MicrophoneSource.cs +++ b/libs/unity/library/Runtime/Scripts/Media/MicrophoneSource.cs @@ -98,10 +98,21 @@ protected async void OnEnable() { AutoGainControl = _autoGainControl, }; - Source = await DeviceAudioTrackSource.CreateAsync(initConfig); - if (Source == null) + try + { + Source = await DeviceAudioTrackSource.CreateAsync(initConfig); + if (Source == null) + { + throw new Exception("DeviceAudioTrackSource.CreateAsync() returned a NULL source."); + } + } + catch (Exception ex) { - throw new Exception("Failed to create microphone audio source."); + // Disable MicrophoneSource + Debug.LogError("Failed to create audio source for MicrophoneSource component; disabling it."); + enabled = false; + // Throw again to log the exception message with a callstack + throw ex; } IsStreaming = true; diff --git a/libs/unity/library/Runtime/Scripts/Media/WebcamSource.cs b/libs/unity/library/Runtime/Scripts/Media/WebcamSource.cs index df4e64f3d..ace56cfc9 100644 --- a/libs/unity/library/Runtime/Scripts/Media/WebcamSource.cs +++ b/libs/unity/library/Runtime/Scripts/Media/WebcamSource.cs @@ -316,10 +316,21 @@ protected async void OnEnable() enableMrc = EnableMixedRealityCapture, enableMrcRecordingIndicator = EnableMRCRecordingIndicator }; - Source = await DeviceVideoTrackSource.CreateAsync(deviceConfig); - if (Source == null) + try + { + Source = await DeviceVideoTrackSource.CreateAsync(deviceConfig); + if (Source == null) + { + throw new Exception("DeviceVideoTrackSource.CreateAsync() returned a NULL source."); + } + } + catch (Exception ex) { - throw new Exception("Failed ot create webcam video source."); + // Disable WebcamSource + Debug.LogError("Failed to create video source for WebcamSource component; disabling it."); + enabled = false; + // Throw again to log the exception message with a callstack + throw ex; } IsStreaming = true;