Unity microphone type on Recorder component causing crash on multiple build targets, editor

@JohnTube replying to your request on Photon Voice 2.0 causing Unity to freeze

As a background, we're using the Photon Microphone type by default, however on one of our Windows 10 laptops the recorder does not become active (will investigate further). We tried using the Unity microphone type to try and solve this, but it causes the editor on Windows 10 and builds on Windows 7, 10 and Android to crash (90% of the time).

To reproduce, set the GetComponent().MicrophoneType = Recorder.MicType.Unity.

From the crash report:

UnityPlayer.dll caused an Access Violation (0xc0000005) in module UnityPlayer.dll at 0033:9d8d7877.
We were able to get the following log when the Unity microphone setup did NOT crash. Notice that the device name is H:ͻ which is unusual. The device is an HTC Vive:

[Networking.Recorder] [PV] MicWrapper: initializing microphone 'Microphone (3- USB Audio Device)', suggested frequency = 24000).
UnityEngine.DebugLogHandler:Internal_Log()
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:LogFormat(LogType, Object, String, Object[])
UnityEngine.Debug:LogFormat(Object, String, Object[])
...

(Filename: C:/Users/john/Desktop/PRIMITIVE/Assets/Photon/PhotonVoice/Code/VoiceLogger.cs Line: 92)

[Networking.Recorder] [PV] MicWrapper: System.ArgumentException: Couldn't acquire device ID for device name H:ͻ
at (wrapper managed-to-native) UnityEngine.Microphone.Start(string,bool,int,int)
at Photon.Voice.Unity.MicWrapper..ctor (System.String device, System.Int32 suggestedFrequency, Photon.Voice.ILogger logger) [0x000bb] in C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\PhotonVoiceApi\Platforms\Unity\MicWrapper.cs:35
UnityEngine.DebugLogHandler:Internal_Log()
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:LogFormat(LogType, Object, String, Object[])
UnityEngine.Debug:LogErrorFormat(Object, String, Object[])
...

(Filename: C:/Users/john/Desktop/PRIMITIVE/Assets/Photon/PhotonVoice/Code/VoiceLogger.cs Line: 66)

[Networking.Recorder] Unity microphone input source creation failure: System.ArgumentException: Couldn't acquire device ID for device name H:ͻ
at (wrapper managed-to-native) UnityEngine.Microphone.Start(string,bool,int,int)
at Photon.Voice.Unity.MicWrapper..ctor (System.String device, System.Int32 suggestedFrequency, Photon.Voice.ILogger logger) [0x000bb] in C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\PhotonVoiceApi\Platforms\Unity\MicWrapper.cs:35 .
UnityEngine.DebugLogHandler:Internal_Log()
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:LogFormat(LogType, Object, String, Object[])
UnityEngine.Debug:LogErrorFormat(Object, String, Object[])
Photon.Voice.Unity.VoiceLogger:LogError(String, Object[]) (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\VoiceLogger.cs:66)
Photon.Voice.Unity.Recorder:CreateLocalVoiceAudioAndSource() (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\Recorder.cs:729)
Photon.Voice.Unity.Recorder:Setup() (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\Recorder.cs:639)
Photon.Voice.Unity.Recorder:Init(VoiceClient, Object) (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\Recorder.cs:593)
Photon.Voice.PUN.PhotonVoiceView:SetupRecorder(Recorder) (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\PUN\PhotonVoiceView.cs:207)
Photon.Voice.PUN.PhotonVoiceView:SetupRecorder() (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\PUN\PhotonVoiceView.cs:175)
Photon.Voice.PUN.PhotonVoiceView:Setup() (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\PUN\PhotonVoiceView.cs:137)
Photon.Voice.PUN.PhotonVoiceView:OnEnable() (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\Code\PUN\PhotonVoiceView.cs:125)
UnityEngine.GameObject:SetActive()
Photon.Pun.PhotonNetwork:NetworkInstantiate(InstantiateParameters, Boolean, Boolean) (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonUnityNetworking\Code\PhotonNetwork.cs:2398)
Photon.Pun.PhotonNetwork:Instantiate(String, Vector3, Quaternion, Byte, Object[]) (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonUnityNetworking\Code\PhotonNetwork.cs:2245)
Assets.NetworkManager:OnJoinedRoom() (at C:\Users\john\Desktop\PRIMITIVE\Assets\NetworkManager.cs:188)
Photon.Realtime.MatchMakingCallbacksContainer:OnJoinedRoom() (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonRealtime\Code\LoadBalancingClient.cs:3334)
Photon.Realtime.LoadBalancingClient:OnEvent(EventData) (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonRealtime\Code\LoadBalancingClient.cs:2463)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer) (at C:\Dev\photon-sdk-dotnet\PhotonDotnet\PeerBase.cs:632)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:\Dev\photon-sdk-dotnet\PhotonDotnet\EnetPeer.cs:553)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:\Dev\photon-sdk-dotnet\PhotonDotnet\PhotonPeer.cs:1428)
Photon.Pun.PhotonHandler:FixedUpdate() (at C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonUnityNetworking\Code\PhotonHandler.cs:130)

(Filename: C:/Users/john/Desktop/PRIMITIVE/Assets/Photon/PhotonVoice/Code/VoiceLogger.cs Line: 66)

[PV] OpusCodec.Encoder: System.ArgumentOutOfRangeException: Must be Mono or Stereo
Parameter name: numChannels
at POpusCodec.OpusEncoder..ctor (POpusCodec.Enums.SamplingRate inputSamplingRateHz, POpusCodec.Enums.Channels numChannels, System.Int32 bitrate, POpusCodec.Enums.OpusApplicationType applicationType, POpusCodec.Enums.Delay encoderDelay) [0x001c5] in C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\PhotonVoiceApi\Core\POpusCodec\OpusEncoder.cs:238
at Photon.Voice.OpusCodec+Encoder`1[T]..ctor (Photon.Voice.VoiceInfo i, Photon.Voice.ILogger logger) [0x00032] in C:\Users\john\Desktop\PRIMITIVE\Assets\Photon\PhotonVoice\PhotonVoiceApi\Core\OpusCodec.cs:39
UnityEngine.DebugLogHandler:Internal_Log()
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
...

(Filename: C:/Users/john/Desktop/PRIMITIVE/Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs Line: 1826)

Comments

  • This is Photon Voice 2.1.1 on Unity 2018.2.17f1
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @john__primitive,

    Thank you for your report!

    Could you try this patched version of Recorder.cs and test again?
  • @JohnTube the patch works. No crashes when using the Unity mic. :)

    Can you suggest a good way to switch from the default Photon mic to the default Unity mic using scripting in the event that the former does not record audio?

    Note: when using the Photon mic on the laptop that doesn't produce sound unless it's set to the Unity mic, the logger says:

    -Setting recorder's source to Photon microphone device 0
    -Setting recorder's source to WindowsAudioInPusher
  • JohnTube
    JohnTube ✭✭✭✭✭
    hey @john__primitive,

    Thank you for testing the patch and confirming it works!

    Your report about Photon mic not working is interesting, we want to know why it doesn't work in the first place:

    - How did you test this? between two clients or using DebugEchoMode?
    - Does this happen with DemoVoiceUI scene also?
    - If DemoVoiceUI shows multiple microphones of type [Photon] in the dropdown list, does switching between them make it work?
    - Does this happen in the Unity Editor and in a build?
    - Could you share full logs with the log levels of the Voice components set to ALL?