Skip to content

Commit 967deaf

Browse files
committed
Fix exception when adding late await instructions
Added try-catch exception logging to awaiter add code because some exceptions can get swallowed See #2
1 parent 442397d commit 967deaf

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

UnityAsync/Assets/UnityAsync/Manager/AsyncManager.ContinuationProcessorGroup.ContinuationProcessor.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.CompilerServices;
3+
using UnityEngine;
34

45
namespace UnityAsync
56
{
@@ -53,20 +54,27 @@ public void Process()
5354
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5455
public void Add(in T cont)
5556
{
56-
if(futureCount == maxIndex)
57+
try
5758
{
58-
AssertQueueSize(futureCount + 1);
59+
if(futureCount >= maxIndex)
60+
{
61+
AssertQueueSize(futureCount + 1);
62+
63+
int newQueueSize = Math.Min(MaxQueueSize, futureQueue.Length * 3 / 2);
5964

60-
int newQueueSize = Math.Min(MaxQueueSize, futureQueue.Length * 3 / 2);
61-
62-
Array.Resize(ref futureQueue, newQueueSize);
63-
Array.Resize(ref currentQueue, newQueueSize);
64-
65-
maxIndex = newQueueSize - 1;
65+
Array.Resize(ref futureQueue, newQueueSize);
66+
Array.Resize(ref currentQueue, newQueueSize);
67+
68+
maxIndex = newQueueSize - 1;
69+
}
70+
71+
futureQueue[futureCount] = cont;
72+
++futureCount;
73+
}
74+
catch(Exception e)
75+
{
76+
Debug.LogException(e);
6677
}
67-
68-
futureQueue[futureCount] = cont;
69-
++futureCount;
7078
}
7179

7280
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)