I've been trying to find out why after a while of using Newton inside Unity 3D, Unity sometime freezes when closing the application.
At first I thought it might be because I forgot to delete a body or something and therefore caused a leak.
But then I found a forum thread that mentioned that Unity waits for all created threads upon exiting, even threads not created by Unity.
When does Newton create new threads?
I assume new threads are created when I call NewtonUpdate() but these threads should be closed as soon as NewtonUpdate() returns right?
Is there anywhere else Newton can create a Thread that keeps running?
After I call NewtonDestroy() there shouldn't be any thread still running right?
I know about NewtonWaitForUpdateToFinish() but isn't that only relevant if using NewtonUpdateAsync() ?
[EDIT]
This is a quote from a Unity staff
When the application exits - UnityEditor or WindowsStandalone player, mono scans all the threads in the application and tries to close them, it also catches threads created by you, even if they were created from C++ not from C#, because mono didn't expect this, at some point it goes into infinite loop.
Mono uses OpenThread (THREAD_ALL_ACCESS, TRUE, threadID) to access the designated thread. So to workaround this problem, you have to create a thread using DELETE restriction by passing special SECURITY_ATTRIBUTES, this way mono will ignore this thread.