microsoft / RoomAliveToolkit

Other
714 stars 191 forks source link

Recording Playback in Unity can't handle loopback #84

Open NPatch opened 6 years ago

NPatch commented 6 years ago

For some reason, if loopback is switched on, with either Read or ReadPreloaded, it only rewinds properly 1-2 times. In a debugging session, I got a System.IO.EndOfStreamException in formatter.Deserialize(skeletonStream) in RATKinectClient. There's no exception handling so at some point this results in exiting the thread and this is not handled in the "restart the stream" code.

Also ReadPreloaded is handled similarly to the Read mode which closes the streams and recreates them(allocation and everything).Isn't this wasteful, considering Preloaded has a memorystream that acts on a byte array that's already set? Could't we just stream.Seek(0,SeekOrigin.Begin)?

NPatch commented 6 years ago

Apparently the loopback issue is because of the EndOfStreamException and some IOExceptions that can happen. There's no try/catch and it happens on one thread at a time, and not directly, so each time, the uncaught exceptions will crash the thread. And they can happen by any stream.