wit-ai / wit-unity

Wit-Unity is a Unity C# wrapper around the the Wit.ai rest APIs and is a core component of Voice SDK.
Other
78 stars 20 forks source link

Application crashes when sending voice data if not connected to the internet #69

Closed jesperlundqvist closed 2 years ago

jesperlundqvist commented 2 years ago

If the device is not connected to the internet we get an Http error which is not handled. When running in the Unity editor or as a development build, this produces the stack trace as you can see below. However, when running a build without the development tag checked, the application crashes.

This can be reproduced in the Unity editor by turning off the internet adapter on your computer, which will give you the stack trace below after speaking into the microphone. The crash can be reproduced on Oculus Quest 2 by disabling WiFi in the settings and speaking a word into the microphone.

This is using the latest Oculus Voice SDK (version 37).

Http Request Failed [1]: Error: NameResolutionFailure
Request Stack Trace:
  at System.Environment.get_StackTrace () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at Facebook.WitAi.WitRequest.Request () [0x0006a] in C:\...\Assets\Oculus\Voice\Lib\Wit.ai\Scripts\Runtime\WitRequest.cs:281 
  at Facebook.WitAi.Wit.ActivateImmediately (Facebook.WitAi.Configuration.WitRequestOptions requestOptions) [0x000d8] in C:\...\Assets\Oculus\Voice\Lib\Wit.ai\Scripts\Runtime\Wit.cs:357 
  at Facebook.WitAi.Wit.OnSampleReady (System.Int32 sampleCount, System.Single[] sample, System.Single levelMax) [0x001d9] in C:\...\Assets\Oculus\Voice\Lib\Wit.ai\Scripts\Runtime\Wit.cs:219 
  at Facebook.WitAi.Lib.Mic+<ReadRawAudio>d__57.MoveNext () [0x0013d] in C:\...\Assets\Oculus\Voice\Lib\Wit.ai\Scripts\Runtime\Lib\Mic.cs:309 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <41d34619c06946aebeba0ca1ee6d765b>:0 
Response Stack Trace:
  at System.Net.WebConnection+<Connect>d__16.MoveNext () [0x00044] in <b5226d7672da4aeaa36d32bf1166a63b>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Net.WebConnection+<InitConnection>d__19.MoveNext () [0x000cc] in <b5226d7672da4aeaa36d32bf1166a63b>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Net.WebOperation+<Run>d__54.MoveNext () [0x000a0] in <b5226d7672da4aeaa36d32bf1166a63b>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x0001d] in <b5226d7672da4aeaa36d32bf1166a63b>:0 
  at Facebook.WitAi.WitRequest.HandleResponse (System.IAsyncResult ar) [0x0001f] in C:\...\Assets\Oculus\Voice\Lib\Wit.ai\Scripts\Runtime\WitRequest.cs:428 
UnityEngine.Debug:LogError (object)
Facebook.WitAi.WitRequest:HandleResponse (System.IAsyncResult) (at Assets/Oculus/Voice/Lib/Wit.ai/Scripts/Runtime/WitRequest.cs:549)
System.Net.HttpWebRequest:BeginGetResponse (System.AsyncCallback,object)
Facebook.WitAi.WitRequest:StartResponse () (at Assets/Oculus/Voice/Lib/Wit.ai/Scripts/Runtime/WitRequest.cs:393)
Facebook.WitAi.WitRequest:HandleRequestStream (System.IAsyncResult) (at Assets/Oculus/Voice/Lib/Wit.ai/Scripts/Runtime/WitRequest.cs:583)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
yolanother commented 2 years ago

Thanks for the stack trace. These should be handled and addressable from the AppVoiceExperiences.events.onError event. We still log them out to the console. If the exception isn't being caught and passed to the onError event that's a bug. I'll take a look.

yolanother commented 2 years ago

I have a fix for this prepped. It should be pushed in the next 24 hr o so.

yolanother commented 2 years ago

This should now be fixed as of https://github.com/wit-ai/wit-unity/commit/c5304e1ed7cb86ca2a79bc7eb1ed9ad7db94e31b