Skip to content

Commit 00a4546

Browse files
committed
don't interrupt the whole scheduled batch if one of the callbacks throws. just log the exception instead (see #38)
also update Unity and add some minor cosmetic changes
1 parent 9b2481f commit 00a4546

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 2021.3.45f1
2-
m_EditorVersionWithRevision: 2021.3.45f1 (0da89fac8e79)
1+
m_EditorVersion: 2021.3.45f2
2+
m_EditorVersionWithRevision: 2021.3.45f2 (88f88f591b2e)

projects/TinkState-Unity-Test/TinkState-Unity-Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<Reference Include="UnityEngine">
28-
<HintPath>../../unity-dlls/UnityEngine.dll</HintPath>
27+
<Reference Include="UnityEngine.CoreModule">
28+
<HintPath>../../unity-dlls/UnityEngine.CoreModule.dll</HintPath>
2929
</Reference>
3030
<Reference Include="UnityEngine.TestRunner">
3131
<HintPath>../../unity-dlls/UnityEngine.TestRunner.dll</HintPath>

projects/TinkState-Unity/TinkState-Unity.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<Reference Include="UnityEngine">
19-
<HintPath>../../unity-dlls/UnityEngine.dll</HintPath>
18+
<Reference Include="UnityEngine.CoreModule">
19+
<HintPath>../../unity-dlls/UnityEngine.CoreModule.dll</HintPath>
2020
</Reference>
2121
</ItemGroup>
2222

src/TinkState-Unity/Runtime/UnityBatchScheduler.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ void Progress(float maxSeconds)
5050
// we have two queues and swap between them to avoid allocating a new list every time
5151
var currentQueue = queue;
5252
queue = nextQueue;
53-
foreach (var o in currentQueue) o.Run();
53+
foreach (var o in currentQueue)
54+
{
55+
try
56+
{
57+
o.Run();
58+
}
59+
catch (Exception e)
60+
{
61+
Debug.LogException(e);
62+
}
63+
}
5464
currentQueue.Clear();
5565
nextQueue = currentQueue;
5666
}
@@ -62,7 +72,7 @@ void Progress(float maxSeconds)
6272
}
6373
}
6474

65-
float GetTimeStamp()
75+
static float GetTimeStamp()
6676
{
6777
return Time.realtimeSinceStartup;
6878
}
@@ -95,7 +105,7 @@ static PlayerLoopSystem[] AppendLoopSystem(PlayerLoopSystem[] subSystemList, Pla
95105

96106
static int FindLoopSystemIndex(PlayerLoopSystem[] subSystemList, Type systemType)
97107
{
98-
for (int i = 0; i < subSystemList.Length; i++)
108+
for (var i = 0; i < subSystemList.Length; i++)
99109
{
100110
if (subSystemList[i].type == systemType)
101111
{

src/TinkState-Unity/Tests/TestUnityBatchScheduler.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using System.Collections;
3+
using System.Collections.Generic;
24
using NUnit.Framework;
35
using UnityEngine.TestTools;
46
using TinkState;
@@ -104,4 +106,30 @@ void BindCallback(int value)
104106
yield return null;
105107
Assert.That(bindingCalls, Is.EqualTo(3));
106108
}
107-
}
109+
110+
[UnityTest]
111+
public IEnumerator TestBindingExceptionNotStoppingProcessing()
112+
{
113+
var state = Observable.State(10);
114+
var calls = new List<string>();
115+
var binding1Called = false;
116+
state.Bind(value =>
117+
{
118+
if (!binding1Called)
119+
{
120+
binding1Called = true;
121+
calls.Add("a");
122+
}
123+
else throw new Exception("FAIL");
124+
});
125+
state.Bind(value =>
126+
{
127+
calls.Add("b");
128+
});
129+
Assert.That(calls, Is.EquivalentTo(new [] {"a", "b"}));
130+
state.Value = 15;
131+
yield return null;
132+
LogAssert.Expect(LogType.Exception, "Exception: FAIL");
133+
Assert.That(calls, Is.EquivalentTo(new [] {"a", "b", "b"}));
134+
}
135+
}
1.36 MB
Binary file not shown.

unity-dlls/UnityEngine.dll

-4.11 MB
Binary file not shown.

0 commit comments

Comments
 (0)