ExtendRealityLtd / VRTK

An example of how to use the Tilia packages to create great content with VRTK v4.
https://www.vrtk.io/
MIT License
3.69k stars 993 forks source link

Physics.IgnoreCollision leads to non-deterministic Unity editor crash #634

Closed Zenopheus closed 8 years ago

Zenopheus commented 8 years ago

The Unity editor crashes Every so often (1 out of 5 times?) when I press the "play" button to close my program. It can also happen (more rarely) while running my program. Usually I only see this:

  d3d11.dll caused an Access Violation (0xc0000005)
    in module d3d11.dll at 0033:f7ea9804.

Sometimes the access violation is caught inside Unity.exe. After many days I finally got a stack trace of value:

0x000000014022DA9B (Unity) sorted_vector<Collider * __ptr64,std::less<Collider * __ptr64>,std::allocator<Collider * __ptr64> >::erase_one<Collider * __ptr64>
0x0000000140F769F6 (Unity) Collider::Deactivate
0x000000014004A4E2 (Unity) GameObject::ActivateAwakeRecursivelyInternal
0x000000014004A5CC (Unity) GameObject::ActivateAwakeRecursively
0x000000014004A8A6 (Unity) GameObject::Deactivate
0x00000001403CD583 (Unity) DestroyGameObjectHierarchy
0x00000001403D0F9D (Unity) DestroyObjectHighLevel
0x0000000140464526 (Unity) DestroyWorldObjects
0x0000000140B6D55B (Unity) EditorSceneManager::RestoreSceneBackups
0x0000000140BDB057 (Unity) Application::ExitPlayMode
0x0000000140BDB44B (Unity) Application::SetIsPlaying
0x0000000140BDBF26 (Unity) Application::TickTimer
0x0000000140E3D91E (Unity) FindMonoBinaryToUse
0x0000000140E3EF4C (Unity) WinMain
0x00000001415BCA40 (Unity) strnlen
0x00007FFCCE448364 (KERNEL32) BaseThreadInitThunk

This seems to be a known issue with Unity that was never properly addressed.

I tracked it down to IgnoreCollisions in VRTK_PlayerPresence. Depending on the situation the colliders being passed to Physics.IgnoreCollision are not active which can lead to this problem. I have not experienced a crash since patching the code. Here is what I did:

        private void IgnoreCollisions(Collider[] colliders, bool state)
        {
            var collider = GetComponent<Collider>();
            if (collider.gameObject.activeInHierarchy)
            {
                foreach (var controllerCollider in colliders)
                {
                    if (controllerCollider.gameObject.activeInHierarchy)
                    {
                      Physics.IgnoreCollision(collider, controllerCollider, state);
                    }
                }
            }
        }
DevonGrandahl commented 8 years ago

Thank you! This problem cropped up last night for seemingly no reason and I spent several hours trying to debug it. Your fix works perfectly.

thestonefox commented 8 years ago

Thanks for the heads up, I'll get a fix pushed.

thestonefox commented 8 years ago

Should be fixed with https://github.com/thestonefox/SteamVR_Unity_Toolkit/commit/2b9460038c56db1184f02b4247387ab72db9ec01

ghost commented 8 years ago

@Zenopheus Dude, I'm freakin' gonna sacrifice a goat for you tonight for this solution. You are a HERO as you saved me hours if not days!

Zenopheus commented 8 years ago

Thx, I know that pain! On Nov 10, 2016 9:55 AM, "rad1c" notifications@github.com wrote:

@Zenopheus https://github.com/Zenopheus Dude, I'm freakin' gonna sacrifice a goat for you tonight for this solution. You are a HERO!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thestonefox/VRTK/issues/634#issuecomment-259710500, or mute the thread https://github.com/notifications/unsubscribe-auth/AEUWp6oWxOidtOd8RBeYdfRlqfB0UklWks5q8zBdgaJpZM4KRjto .