IEnumerator RecordData()
    {
        while (true)
        {
            yield return(new WaitForEndOfFrame());

            if (recordingStopped)
            {
                continue;
            }

            RecordingDatum datum = new RecordingDatum
            {
                frameTime = Time.time,
                leftEye   = fove.GetLeftEyeVector(),
                rightEye  = fove.GetRightEyeVector()
            };

            dataSlice.Add(datum);

            if (dataSlice.Count >= writeAtDataCount)
            {
                if (!writingDataMutex.WaitOne(3))
                {
                    long excess = dataSlice.Count - writeAtDataCount;
                    if (excess > 1)
                    {
                        Debug.LogError("Data slice is " + excess + " entries over where it should be; this is" +
                                       "indicative of a major performance concern in the data recording and writing" +
                                       "process.");
                    }
                    continue;
                }
                CheckForNullDataToWrite();

                dataToWrite = dataSlice;
                dataSlice   = new List <RecordingDatum>((int)(writeAtDataCount + 1));

                writingDataMutex.ReleaseMutex();

                if (!threadWaitHandle.Set())
                {
                    Debug.LogError("Error setting the event to wake up the file writer thread!");
                }
            }
        }
    }