fix: coroutine managers now handle exceptions

This commit is contained in:
2026-04-10 11:22:40 +03:00
parent 50794d44ba
commit e9d4c3eb64
2 changed files with 41 additions and 17 deletions

View File

@@ -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;

View File

@@ -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