Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback errors (#101) #115

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Runtime/Components/CallbackComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ static class CallbackUtility {
internal static void Invoke<T>(this EcsWorld world, int entity) where T : struct, ICallback {
var callbackPool = world.GetPool<T>();
if (callbackPool.Has(entity)) {
callbackPool.Get(entity).Callback();
try {
callbackPool.Get(entity).Callback();
} catch (Exception e) {
var error = new Exception($"Error in {typeof(T)} callback", e);
UnityEngine.Debug.LogError(error);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Runtime/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ public static void Run<TGroup>(float deltaTime) where TGroup : struct {
AssertNotRunning();
if (_groupFilters.TryGetValue(typeof(TGroup), out var filter)) {
_runState.Set(filter, deltaTime);
_systems.Run();
Run();
}
}

public static void ManualUpdate(int entity, float deltaTime) {
AssertNotRunning();
_runState.Set(entity, deltaTime);
_systems.Run();
Run();
}

public static void Sync(int entity) => ManualUpdate(entity, 0);
Expand Down
24 changes: 23 additions & 1 deletion Tests/OnUpdateTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEngine;
using NUnit.Framework;
using System;
using UnityEngine;

namespace PeachyTween.Tests {
public class OnUpdateTest : BaseTweenTest {
Expand Down Expand Up @@ -56,5 +57,26 @@ public void RemoveOnUpdate() {
Assert.AreEqual(1, aCount, $"first {nameof(OnUpdate)} callback called");
Assert.AreEqual(0, bCount, $"second {nameof(OnUpdate)} callback was not called");
}

[Test]
public void SyncOnUpdate() {
var caught = null as Exception;
var onUpdate = 0;
var tween = Peachy.Tween(0f, 1f, 1f, _ => {});

tween.OnUpdate(() => {
onUpdate++;
try {
tween.Sync();
} catch (Exception e) {
caught = e;
}
});

tween.ManualUpdate(0.5f);

Assert.AreEqual(1, onUpdate, $"{nameof(OnUpdate)} callback called");
Assert.True(caught is Exception, $"{nameof(Exception)} caught");
}
}
}