Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Mono Upgrade UniRx Library with .Net 4.6 API Error

Discussion in 'Experimental Scripting Previews' started by ProtonOne, Jun 23, 2017.

  1. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    Unity Version 5.5.0xMono-Runtime-Upgrade-b9
    API: .Net 4.6
    UniRx Scripting Define Symbols
    ENABLE_MONO_BLEEDING_EDGE_EDITOR;ENABLE_MONO_BLEEDING_EDGE_STANDALONE
    Status: Works!

    Unity Version 2017.1.0b10 & 2017.1.0b8
    API: .Net 4.6
    UniRx Scripting Define Symbols
    ENABLE_MONO_BLEEDING_EDGE_EDITOR;ENABLE_MONO_BLEEDING_EDGE_STANDALONE
    Status: Error!



    Test Script EveryUpdateTest.cs
    Code (CSharp):
    1. using UniRx;
    2. using UnityEngine;
    3.  
    4. public class EveryUpdateTest : MonoBehaviour {
    5.     void Start () {
    6.         Observable.EveryUpdate()
    7.             .Subscribe(_ => Debug.Log("test") )
    8.             .AddTo(this);
    9.     }  
    10. }
    Other notes:
    - I posted an issue report for the author of UniRx:
    https://github.com/neuecc/UniRx/issues/230

    - UniRx is a library that implements Rx interface (like the System.IObservable) which is now part of .Net 4.6. So using the compiler define symbols above is necessary.

    - UniRx website: https://github.com/neuecc/UniRx

    I am not sure if this is a UniRx or Unity problem, I can submit a Unity bug report with example project if needed.
     
  2. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I suspect UniRx sets up a synchronization context for the main thread. Unity now has its own one and calls it every frame:
    Code (CSharp):
    1. if (SynchronizationContext.Current != null)
    2. {
    3.     ((UnitySynchronizationContext)SynchronizationContext.Current).Exec();
    4. }
    If the current synchronization context if not UnitySynchronizationContext, we get invalid cast exception. Unity could change this code to
    Code (CSharp):
    1. var context = SingleThreadSynchronizationContext.Current as UnitySynchronizationContext;
    2. context?.ExecuteTasks();
    to manage such cases. However, I'm not sure that overriding the Unity's context with a custom one may be considered as a good idea. I guess, it's not.
     
    mkderoy likes this.
  3. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
    We will look into making our synchronization context invocation more robust. Please file bug and post # here. Thanks!
     
    MechEthan likes this.
  4. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    Bug # 924070
     
    Qbit86 likes this.