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 CoroutineManager : Behaviour, IUpdate
|
||||
@@ -21,6 +23,8 @@ public class CoroutineManager : Behaviour, IUpdate
|
||||
void IUpdate.Update()
|
||||
{
|
||||
for (int i = enumerators.Count - 1; i >= 0; i--)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (enumerators[i].Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
||||
continue;
|
||||
@@ -28,6 +32,14 @@ public class CoroutineManager : Behaviour, IUpdate
|
||||
if (!enumerators[i].MoveNext())
|
||||
enumerators.RemoveAt(i);
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
ILogger.Shared.LogError(this, $"Coroutine failed, removing from execution.");
|
||||
ILogger.Shared.LogException(this, exception);
|
||||
ILogger.Shared.LogTrace(exception.StackTrace);
|
||||
enumerators.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CoroutineManager() => Priority = int.MinValue;
|
||||
|
||||
@@ -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,6 +49,8 @@ public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IEnumerator top = stack.Peek();
|
||||
|
||||
if (top.Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
||||
@@ -66,6 +70,14 @@ public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
ILogger.Shared.LogError(this, $"Coroutine failed, removing from execution.");
|
||||
ILogger.Shared.LogException(this, exception);
|
||||
ILogger.Shared.LogTrace(exception.StackTrace);
|
||||
RemoveCoroutineAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CoroutineStack
|
||||
|
||||
Reference in New Issue
Block a user