fix: coroutine managers now handle exceptions
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Engine.Core.Debug;
|
||||
|
||||
namespace Engine.Core;
|
||||
|
||||
public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
||||
@@ -47,23 +49,33 @@ public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
||||
continue;
|
||||
}
|
||||
|
||||
IEnumerator top = stack.Peek();
|
||||
|
||||
if (top.Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
||||
continue;
|
||||
|
||||
if (top.Current is IEnumerator nested)
|
||||
try
|
||||
{
|
||||
stack.Push(nested);
|
||||
continue;
|
||||
IEnumerator top = stack.Peek();
|
||||
|
||||
if (top.Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
||||
continue;
|
||||
|
||||
if (top.Current is IEnumerator nested)
|
||||
{
|
||||
stack.Push(nested);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!top.MoveNext())
|
||||
{
|
||||
stack.Pop();
|
||||
if (stack.Count != 0)
|
||||
stack.Peek().MoveNext();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!top.MoveNext())
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
stack.Pop();
|
||||
if (stack.Count != 0)
|
||||
stack.Peek().MoveNext();
|
||||
continue;
|
||||
ILogger.Shared.LogError(this, $"Coroutine failed, removing from execution.");
|
||||
ILogger.Shared.LogException(this, exception);
|
||||
ILogger.Shared.LogTrace(exception.StackTrace);
|
||||
RemoveCoroutineAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user