fix: coroutine managers now handle exceptions
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using Engine.Core.Debug;
|
||||||
|
|
||||||
namespace Engine.Core;
|
namespace Engine.Core;
|
||||||
|
|
||||||
public class CoroutineManager : Behaviour, IUpdate
|
public class CoroutineManager : Behaviour, IUpdate
|
||||||
@@ -21,6 +23,8 @@ public class CoroutineManager : Behaviour, IUpdate
|
|||||||
void IUpdate.Update()
|
void IUpdate.Update()
|
||||||
{
|
{
|
||||||
for (int i = enumerators.Count - 1; i >= 0; i--)
|
for (int i = enumerators.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (enumerators[i].Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
if (enumerators[i].Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
||||||
continue;
|
continue;
|
||||||
@@ -28,6 +32,14 @@ public class CoroutineManager : Behaviour, IUpdate
|
|||||||
if (!enumerators[i].MoveNext())
|
if (!enumerators[i].MoveNext())
|
||||||
enumerators.RemoveAt(i);
|
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;
|
public CoroutineManager() => Priority = int.MinValue;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using Engine.Core.Debug;
|
||||||
|
|
||||||
namespace Engine.Core;
|
namespace Engine.Core;
|
||||||
|
|
||||||
public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
||||||
@@ -47,6 +49,8 @@ public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
IEnumerator top = stack.Peek();
|
IEnumerator top = stack.Peek();
|
||||||
|
|
||||||
if (top.Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
if (top.Current is ICoroutineYield coroutineYield && coroutineYield.Yield())
|
||||||
@@ -66,6 +70,14 @@ public class NestedCoroutineManager : Behaviour, IUpdate, ICoroutineManager
|
|||||||
continue;
|
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
|
private class CoroutineStack
|
||||||
|
|||||||
Reference in New Issue
Block a user