0
Fixed

Coroutine flow throws exception if disabled immediately

cooloon 7 months ago • updated by Lazlo Bonin (Lead Developer) 2 months ago 5 1 duplicate

What Happened:

Coroutine flow throws an exception when flow is disabled without executing any wait unit.

Steps to Reproduce:

  1. Create a flow graph below and put it in some scene. 
  2. Play the scene. If the 'Skip Wait' boolean value at the bottom left is True, NotSupportedException will be thrown. Otherwise the flow works perfectly.

Problem:

The exception is thrown from Flow.StopCoroutine() method. This method expect `coroutine` property not to be null (`isCoroutine` is false if `coroutine` is null).

public void StopCoroutine()
{
    if (!isCoroutine)
    {
        throw new NotSupportedException("Stop may only be called on coroutines.");
    }
    coroutineStopRequested = true;
}

But `coroutine` property is assigned like below in the Flow.StartCoroutine() method. In this code, `coroutine` is assigned after the first call of MoveNext().

coroutine = coroutineRunner.StartCoroutine(Coroutine(port));

Possible Workaround:

You can put 'Wait For End of Frame' unit just before the set_enabled unit.


Stack Trace:

NotSupportedException: Stop may only be called on coroutines.
Bolt.Flow.StopCoroutine () (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:255)
Bolt.EventUnit`1[Bolt.EmptyEventArgs].StopListening (Ludiq.GraphStack stack) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Events/EventUnit.cs:89)
Bolt.FlowGraph.StopListening (Ludiq.GraphStack stack) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/FlowGraph.cs:53)
Bolt.FlowMachine.OnDisable () (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/FlowMachine.cs:37)
UnityEngine.Behaviour:set_enabled(Boolean)
Ludiq.InstancePropertyAccessor`2:SetValueUnsafe(Object, Object) (at C:/Users/lazlo/Projects/Bolt1/Package/Ludiq.Core/Runtime/Reflection/Optimization/InstancePropertyAccessor.cs:144)
Ludiq.InstancePropertyAccessor`2:SetValue(Object, Object) (at C:/Users/lazlo/Projects/Bolt1/Package/Ludiq.Core/Runtime/Reflection/Optimization/InstancePropertyAccessor.cs:125)
Ludiq.Member:Set(Object) (at C:/Users/lazlo/Projects/Bolt1/Package/Ludiq.Core/Runtime/Reflection/Member.cs:830)
Bolt.SetMember:Assign(Flow) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Codebase/SetMember.cs:112)
Bolt.Flow:InvokeDelegate(ControlInput) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:394)
Bolt.<invokecoroutine>d__54:MoveNext() (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:337)
Bolt.<invokecoroutine>d__54:MoveNext() (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:341)
Bolt.<coroutine>d__52:MoveNext() (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:263)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Bolt.Flow:StartCoroutine(ControlOutput, ICollection`1) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:248)
Bolt.EventUnit`1:Run(Flow) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Events/EventUnit.cs:148)
Bolt.EventUnit`1:Trigger(GraphReference, EmptyEventArgs) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Events/EventUnit.cs:123)
Bolt.<>c__DisplayClass14_0:<startlistening>b__0(EmptyEventArgs) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Events/EventUnit.cs:68)
Bolt.EventBus:Trigger(EventHook, EmptyEventArgs) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventBus.cs:65)
Bolt.EventMachine`2:TriggerRegisteredEvent(EventHook, EmptyEventArgs) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventMachine.cs:42)
Bolt.EventMachine`2:TriggerEvent(String) (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventMachine.cs:14)
Bolt.EventMachine`2:OnEnable() (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventMachine.cs:84)
Bolt.FlowMachine:OnEnable() (at C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/FlowMachine.cs:26)</startlistening></coroutine></invokecoroutine></invokecoroutine>
Bolt Version:
1.4.0f11
Unity Version:
2017.4.15f1 for Mac
.NET Version:
3.5
GOOD, I'M SATISFIED
Satisfaction mark by cooloon 7 months ago

Duplicates 1

+2
Working on Fix

Good catch (& thanks for the thorough report), I'll have a look at why this happens!

+1
Fixed in Next Version

Fixed for v.1.4.0f12 :)

+2
Under Review

Hi Nikita,

Sorry for the late reply. This issue was fixed in v.1.4.1b1. Unfortunately 1.4.1 is still in beta (currently beta 3), but we are going as fast as we can to get it to stable. 

You can download the latest beta here in the mean time:

https://ludiq.io/bolt/download/1.4.1b3

Yeah, actually I've got already, but thanks for your honest caring!