Skip to content

Commit 39bfba2

Browse files
authored
Merge pull request #133 from timcassell/fix-il2cpp
Fix IL2CPP bugs
2 parents 86f7223 + 0541eb5 commit 39bfba2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

ProtoPromise_Unity/Assets/Plugins/ProtoPromise/Core/Promises/Internal/PromiseInternal.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ internal static bool TryWaitForCompletion(PromiseRefBase promise, short promiseI
135135
if (waiter._isHookingUp)
136136
{
137137
waiter._isHookingUp = false;
138-
waiter._didWaitSuccessfully = Monitor.Wait(waiter, timeout);
138+
// If timeout is 0, Monitor.Wait returns true when it should return false in IL2CPP. So we have to explicitly check for that value.
139+
waiter._didWaitSuccessfully = timeout != TimeSpan.Zero && Monitor.Wait(waiter, timeout);
139140
Thread.MemoryBarrier(); // Make sure _didWait is written last.
140141
waiter._didWait = true;
141142
return waiter._didWaitSuccessfully;

ProtoPromise_Unity/Assets/Plugins/ProtoPromiseTests/Helpers/TestHelper.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#if PROTO_PROMISE_DEBUG_ENABLE || (!PROTO_PROMISE_DEBUG_DISABLE && DEBUG)
1+
#if UNITY_5_5 || NET_2_0 || NET_2_0_SUBSET
2+
#define NET_LEGACY
3+
#endif
4+
5+
#if PROTO_PROMISE_DEBUG_ENABLE || (!PROTO_PROMISE_DEBUG_DISABLE && DEBUG)
26
#define PROMISE_DEBUG
37
#else
48
#undef PROMISE_DEBUG
@@ -99,6 +103,18 @@ public static void Setup()
99103
{
100104
try
101105
{
106+
#if ENABLE_IL2CPP && !NET_LEGACY && !UNITY_2022_1_OR_NEWER
107+
// ExceptionDispatchInfo.Throw() generates a new Exception object instead of throwing the original object in IL2CPP, causing the Assert to fail.
108+
// This was fixed in Unity 2022. To avoid the tests failing, we instead have to check the object's type and message.
109+
if (s_expectedUncaughtRejectValue is Exception)
110+
{
111+
Exception expected = (Exception) s_expectedUncaughtRejectValue;
112+
Assert.AreEqual(expected.GetType(), e.Value.GetType());
113+
Exception actual = (Exception) e.Value;
114+
Assert.AreEqual(expected.Message, actual.Message);
115+
return;
116+
}
117+
#endif
102118
Assert.AreEqual(s_expectedUncaughtRejectValue, e.Value);
103119
}
104120
catch (Exception ex)

0 commit comments

Comments
 (0)