Late to the party, but I've seen this issue come up in several threads here (and had it myself):
The SaccadeVR project actually does a neat workaround that works for most use cases and a freeze because of the ongoing while/for loop in the eye tracking:
You can hand over every end condition you might want to the loop in the separate callback thread through an intermediate function. In my case, it's a simple bool:
static bool GetEndCondition()
{
return isQuitting;
}
that static bool is set OnApplicationQuit
private void OnApplicationQuit()
{
isQuitting = true;
}
and the intermediate function called within the loop:
while (FrameCount < MaxFrameCount)
{
CppFrameCount++;
// Break loop when necessary so the Callback does not freeze Unity, e.g. when quitting the application
bool endCondition;
endCondition = GetEndCondition();
if (endCondition) // if needed compare the ending condition e.g. with the FrameCount or Unix time here
break;
// do stuff
}
Voilà. No more freeze on closing the Runtime & Stopping the Editor.