UniRxを使ってて気になったこと
AddToしているのものをIDisposable.Dispose()して、そのあとオブジェクトを廃棄したら二重解放になる?
結論、ならないので気にしなくて大丈夫な模様。
下記のコードでは、Disposeした後、AddToしたgameObjectを破棄しているが、特にエラーは発生しなかった。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UniRx; public class Test : MonoBehaviour { int counter = 0; System.IDisposable disposer; void Start () { disposer = gameObject.ObserveEveryValueChanged( _ => counter ).Subscribe( x => Debug.Log( x ) ).AddTo( gameObject ); } void Update () { counter++; if( counter == 1 ) { disposer.Dispose(); } if( counter == 2 ) { Destroy( gameObject ); } //Disposeした後に、gameObjectを破棄したら二重解放でエラーになる? } }
もしかしてiOS+Monoだと動かない?
iOS用 + Scripting BackendをMonoにするとエラーが発生するようです。
ExecutionEngineException: Attempting to JIT compile method 'UniRx.UnityEqualityComparer/RuntimeTypeHandlerCache`1<int>:.cctor ()' while running with --aot-only. Rethrow as TypeInitializationException: An exception was thrown by the type initializer for RuntimeTypeHandlerCache`1 at UniRx.ObserveExtensions.ObserveEveryValueChanged[GameObject,Int32] (UnityEngine.GameObject source, System.Func`2 propertySelector, FrameCountType frameCountType, Boolean fastDestroyCheck) [0x00000] in <filename unknown>:0 at Test.Start () [0x00000] in <filename unknown>:0
デバッグ用途ではビルド時間短縮のためにMonoを使うことが多いので、コレは痛い。
どうしたものか。