ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.53k stars 363 forks source link

Unity 2019.1.0f2 crashes with Zenject on "Play" button press. #628

Open IvanMurzak opened 5 years ago

IvanMurzak commented 5 years ago

I can't even start the scene when Zenject exists in the scene and as ScriptableObject installer. Is it my mistake or Unity or Zenject?

0x000001730062E747 (UnityEngine.CoreModule) UnityEngine.GameObject.GetComponentFastPath()
0x000001730062E58B (UnityEngine.CoreModule) UnityEngine.GameObject.GetComponent()
0x000001728D31E703 (Zenject) <>c__DisplayClass12_0.<GetRootGameObjects>b__1()
0x000001730006BF77 (System.Core) WhereArrayIterator`1.MoveNext()
0x000001728D31D9B4 (Zenject) Zenject.Internal.ZenUtilInternal.AddStateMachineBehaviourAutoInjectersInScene()
0x000001728D31D63B (Zenject) Zenject.SceneContext.GetInjectableMonoBehaviours()
0x000001728D31AB29 (Zenject) Zenject.SceneContext.Install()
0x000001728969823B (Zenject) Zenject.SceneContext.RunInternal()
0x0000017289697DD5 (Zenject) Zenject.RunnableContext.Run()
0x0000017289697BFB (Zenject) Zenject.RunnableContext.Initialize()
0x0000017289697A9B (Zenject) Zenject.SceneContext.Awake()
0x0000017299E47868 (mscorlib) System.Object.runtime_invoke_void__this__()
svermeulen commented 5 years ago

Hmm I tried running the sample project in Unity 2019 and it runs without issue. And the sample projects use scriptable object installer. Could you provide a minimal reproducible example?

IvanMurzak commented 5 years ago

Yeah, I'm ready for anything for fixing it. Because it locks me. Just give me some time to preparing the example.

Update: Some additional info just in case. the same Unity crash reproduces with Unity 2019.2.x (where X is from 4 to 13 I tested them all)

IvanMurzak commented 5 years ago

Editor.log The same Unity 2019.1.1 crash with logs about Zenject dll I sent example project with instruction to reproduce to your email which is publicly available at your GitHub account. But I must warn you. The crash is very randomly, but if you once trigger it, it reproduces many times. And If you want to try to debug unity editor I'm not sure it reproduces in debug mode.

svermeulen commented 5 years ago

If you can't reproduce it as a minimal example then my guess is that it's not zenject's fault. I'm also reluctant to try and debug the issue starting with your entire project

IvanMurzak commented 5 years ago

It is still my project but I minimalized the scene to just Camera and SceneContext objects. It reproduces in that scene. If remove or deactivate SceneContext from the scene - the crash is gone. https://youtu.be/JNgb5JybOmU

Sent you zip archive by email.

IvanMurzak commented 5 years ago

Unity QA asks me "Are you creating a delegate from a DynamicMethod?" at the crash report. Does Zenject is making something like that?

renaudbedard commented 5 years ago

I've been getting the same exact crash on Unity 2018.4.4f1, same stack trace and same random occurence on play. Was there any progress on this issue?

jonesah commented 4 years ago

We are having the same issue. Quite blocking. Any progress here @svermeulen ?

theandylee commented 4 years ago

We're having the same random crashes on different 2019.2.x versions, which really slows down the work. The stack trace is just the same as Ivan's. Hope you'll be able to find out what the problem is.

Wasabi2007 commented 4 years ago

So we run into the same problem on our project. As far as we can tell it's an unity internal Issue. We guess that on the basis that the bad commit which introduced this problem where pure asset changes which where not even part of any Resource Folder. After some trail and error we found a fix which seems to at least alleviate the problem. It's this line: https://github.com/modesttree/Zenject/blob/514e533a33c5bfa9d0ed14950faf9889fb7ee0ae/UnityProject/Assets/Plugins/Zenject/Source/Util/ZenUtilInternal.cs#L241 If you use the GetComponent call as last condition instead of being the second last one it seems to reduce the problem to a point where we cant reproduce it anymore.

I hope It helps 🙂

IvanMurzak commented 3 years ago

I reproduced the error again with another project and another Unity version. It reproduces every time when I press "Play" button in Unity Editor. Unity 2019.4.18

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) UnityEngine.GameObject.GetComponentFastPath (UnityEngine.GameObject,System.Type,intptr) [0x00015] in <17ad9609ae064f2c9315931ff97adcf1>:0
  at UnityEngine.GameObject.GetComponent<T_REF> () [0x00021] in <17ad9609ae064f2c9315931ff97adcf1>:0
  at Zenject.Internal.ZenUtilInternal/<>c__DisplayClass12_0.<GetRootGameObjects>b__1 (UnityEngine.GameObject) [0x00000] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Util\ZenUtilInternal.cs:240
  at System.Linq.Enumerable/WhereArrayIterator`1<TSource_REF>.MoveNext () [0x00033] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at Zenject.Internal.ZenUtilInternal.AddStateMachineBehaviourAutoInjectersInScene (UnityEngine.SceneManagement.Scene) [0x0002d] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Util\ZenUtilInternal.cs:95
  at Zenject.SceneContext.GetInjectableMonoBehaviours (System.Collections.Generic.List`1<UnityEngine.MonoBehaviour>) [0x0000d] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Install\Contexts\SceneContext.cs:365
  at Zenject.SceneContext.Install () [0x00117] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Install\Contexts\SceneContext.cs:250
  at Zenject.SceneContext.RunInternal () [0x00018] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Install\Contexts\SceneContext.cs:134
  at Zenject.RunnableContext.Run () [0x00015] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Install\Contexts\RunnableContext.cs:36
  at Zenject.RunnableContext.Initialize () [0x00016] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Install\Contexts\RunnableContext.cs:22
  at Zenject.SceneContext.Awake () [0x00002] in F:\Projects\Unity\E-MasterGame\Assets\Plugins\Zenject\Source\Install\Contexts\SceneContext.cs:113
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00020] in <9577ac7a62ef43179789031239ba8798>:0

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
IvanMurzak commented 3 years ago

@Wasabi2007 commenting the line 241 really helps. Thank you!

So we run into the same problem on our project. As far as we can tell it's an unity internal Issue. We guess that on the basis that the bad commit which introduced this problem where pure asset changes which where not even part of any Resource Folder. After some trail and error we found a fix which seems to at least alleviate the problem. It's this line:

https://github.com/modesttree/Zenject/blob/514e533a33c5bfa9d0ed14950faf9889fb7ee0ae/UnityProject/Assets/Plugins/Zenject/Source/Util/ZenUtilInternal.cs#L241

If you use the GetComponent call as last condition instead of being the second last one it seems to reduce the problem to a point where we cant reproduce it anymore. I hope It helps 🙂