Skip to content

Instantly share code, notes, and snippets.

@hacha
Created July 7, 2015 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hacha/8bfb174f9722492a83d1 to your computer and use it in GitHub Desktop.
Save hacha/8bfb174f9722492a83d1 to your computer and use it in GitHub Desktop.
こういうコンポーネントを持つオブジェクトを、ストリーム発火前にDestoryするとUniRx内でInvalidOperationExceptionが発生するっぽい
using UnityEngine;
using System.Collections;
using UniRx;
using UniRx.Triggers;
public class Test : MonoBehaviour
{
void Start ()
{
var key = this.UpdateAsObservable()
.Where(_ => Input.GetKeyDown(KeyCode.A))
.First()
.Subscribe(_ => Debug.Log("test"));
}
}
@hacha
Copy link
Author

hacha commented Jul 7, 2015

試した環境
Unity 5.0.2f1
UniRx 4.8.2

例外発生時のスタックトレース

InvalidOperationException: sequence is empty
UniRx.Stubs.m__1B7 (System.Exception ex) (at Assets/UniRx/Scripts/Observer.cs:180)
UniRx.Observer+AnonymousObserver1[UniRx.Unit].OnError (System.Exception error) (at Assets/UniRx/Scripts/Observer.cs:71) UniRx.Observable+AnonymousObservable1+c__AnonStorey117[UniRx.Unit].<>m__1AD (System.Exception ex) (at Assets/UniRx/Scripts/Observable.Creation.cs:35)
UniRx.Observer+AnonymousObserver1[UniRx.Unit].OnError (System.Exception error) (at Assets/UniRx/Scripts/Observer.cs:71) UniRx.Observable+<FirstCore>c__AnonStoreyB71+c__AnonStoreyB81[UniRx.Unit].<>m__15D () (at Assets/UniRx/Scripts/Observable.Paging.cs:687) UniRx.Observer+AnonymousObserver1[UniRx.Unit].OnCompleted () (at Assets/UniRx/Scripts/Observer.cs:87)
UniRx.Observable+AnonymousObservable1+<Subscribe>c__AnonStorey117[UniRx.Unit].<>m__1AE () (at Assets/UniRx/Scripts/Observable.Creation.cs:35) UniRx.Observer+AnonymousObserver1[UniRx.Unit].OnCompleted () (at Assets/UniRx/Scripts/Observer.cs:87)
UniRx.Observer+AnonymousObserver1[UniRx.Unit].OnCompleted () (at Assets/UniRx/Scripts/Observer.cs:87) UniRx.Subject1[UniRx.Unit].OnCompleted () (at Assets/UniRx/Scripts/Subjects/Subject.cs:38)
UniRx.Triggers.ObservableUpdateTrigger.RaiseOnCompletedOnDestroy () (at Assets/UniRx/Scripts/UnityEngineBridge/Triggers/ObservableUpdateTrigger.cs:27)
UniRx.Triggers.ObservableTriggerBase.OnDestroy () (at Assets/UniRx/Scripts/UnityEngineBridge/Triggers/ObservableTriggerBase.cs:52)

@hacha
Copy link
Author

hacha commented Jul 7, 2015

破棄される際にOnCompleted()が呼ばれるところで例外発生してるっぽい。
First()をTake(1)にしたら解決したけど、このOnCompleted()時に例外にならないのは何故なんだろう。

@kenji-andoh
Copy link

First() は空のストリームではエラーだ、空かどうかが判明するのは OnComplete() のときだ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment