何のことか分かりにくいが以下のコードで再現できる。
SharpDX を Unity 上で使うべく GL.IssuePluginEvent に C#の Delegate を渡す実験をしていた。これをやると、Editor 終了時もしくは次回 play 時に UnityEditor が Freeze する(100%)。Unity5.5.3 と Unity2017.1.0beta1 で再現した。 調べてみたところ、
forum.unity3d.com
https://forum.unity3d.com/threads/problem-with-callbacks.87513/
が該当しそうかと思ったがちょっと違う。新しいスレッドを起こしている訳では無いので。 ただ、条件は下記の通り
C#の delegate を関数ポインタとして C に渡す その関数ポインタが異なるスレッドから呼び出される
次に
Investigating Unity hang on second run (multi-threading) - Tedds blog
Background he problem of Unity hangs on second run may have multiple causes and can sometimes be difficult to debug. When searching for an answer I see many with the same problem. I am therefore sharing a my debugging process in hope that it can help others solve their own problem. The problem Unity has ... Read more
https://blog.tedd.no/2016/10/09/investigating-unity-hang-on-second-run-multi-threading/
を当たった。ここで紹介している visualstudio の debug - window - 並列スタックで状況を確認する手法を使ってみたところ以下のようになっていた。
mono_domain_unload が固まっているような気がするぞ。
Unloading Mono domains in multithreaded context
I have a multithreaded application that activate multiple Mono domains from native code.
Each domain has it's own thread.
I use the following code to activate a domain:
///Create a new domain.
m_...
http://stackoverflow.com/questions/10138015/unloading-mono-domains-in-multithreaded-context
mono が delegate から関数ポインタを作るのに使っているらしい invoke wrappers の周りの回収に失敗しているのではないかというような気がする。
mono Bug 463323, 475962 について調べてみた&動的なメソッド呼び出しの実装を追いかけてみた - やこ〜ん SuperNova2
最近 C# なコードを仕事でも使う縁に恵まれているのだが、そこで mono の Delegate.DynamicInvoke 関連で興味深いバグがあると聞いたので、調べてみた。また、せっかくなので Delegate.DynamicInvoke や MethodInfo.Invoke などに端を発するメソッド呼び出しの処理が、mono 内部でどのようにして処理されてゆくのかを追いかけてみた。ref: Bug 463323 – Bug with delegates to dynamic methods ref: Bug 475962 – exception thrown from CreateDe…
http://d.hatena.ne.jp/saiya_moebius/20090319/1237434037
Unity 上で打つ手は見つからなかった・・・