Skip to content

Commit 46a5e07

Browse files
committed
Fixed incorrect enum values being deserialized on some versions of Unity.
Added additional debug info when tests fail.
1 parent 2baac1c commit 46a5e07

File tree

3 files changed

+72
-59
lines changed

3 files changed

+72
-59
lines changed

Plugins/HoudiniEngineUnity/Scripts/Asset/HEU_InputNode.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ internal enum InputObjectType
161161
HDA,
162162
UNITY_MESH,
163163
CURVE,
164-
#if UNITY_2022_1_OR_NEWER
165-
SPLINE,
166-
#endif
167164
TERRAIN,
168165
BOUNDING_BOX,
169-
TILEMAP
166+
TILEMAP,
167+
#if UNITY_2022_1_OR_NEWER
168+
SPLINE
169+
#endif
170170
}
171171

172172

Plugins/HoudiniEngineUnity/Scripts/Utility/HEU_Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static IEquivable<T>[] ConvertArrayToEquivable<T>(this T[] self)
9696
return self.Cast<IEquivable<T>>().ToArray();
9797
}
9898

99-
public static bool ApproximatelyEquals(this float self, float other, float epsilon = 1E-06F)
99+
public static bool ApproximatelyEquals(this float self, float other, float epsilon = 1E-03F)
100100
{
101101
return Mathf.Abs(self - other) < epsilon;
102102
}

Plugins/HoudiniEngineUnity/Scripts/Utility/HEU_TestHelpers.cs

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -306,78 +306,91 @@ public static bool AssertTrueLogEquivalent<T>(List<IEquivableWrapperClass<T>> a,
306306
public static bool AssertTrueLogEquivalent<T>(T[] a, T[] b, ref bool result, string header, string subject,
307307
string optional1 = "", string optional2 = "", string optional3 = "") where T : struct
308308
{
309-
bool bResult = true;
309+
bool bTotalResult = true;
310+
if (!ShouldBeTested(a, b, ref bTotalResult, header, subject))
311+
return true;
310312

311-
if (ShouldBeTested(a, b, ref bResult, header, subject))
313+
int errorCount = 0;
314+
315+
for (int i = 0; i < a.Length; i++)
312316
{
313-
for (int i = 0; i < a.Length; i++)
317+
318+
bool bResult = true;
319+
320+
if (a[i].GetType() == typeof(float))
314321
{
315-
if (a[i].GetType() == typeof(float))
316-
{
317-
float aF = (float)((object)a[i]);
318-
float bF = (float)((object)b[i]);
322+
float aF = (float)((object)a[i]);
323+
float bF = (float)((object)b[i]);
319324

320-
bResult &= aF.ApproximatelyEquals(bF);
321-
if (bResult == false)
322-
{
323-
HEU_Logger.Log(aF + " " + bF);
324-
}
325-
}
326-
else if (a[i].GetType() == typeof(Vector2))
327-
{
328-
Vector2 aV = (Vector2)((object)a[i]);
329-
Vector2 bV = (Vector2)((object)b[i]);
330-
for (int j = 0; j < 2; j++)
331-
{
332-
bResult &= aV[j].ApproximatelyEquals(bV[j]);
333-
}
334-
}
335-
else if (a[i].GetType() == typeof(Vector3))
325+
bResult &= aF.ApproximatelyEquals(bF);
326+
if (bResult == false)
336327
{
337-
Vector3 aV = (Vector3)((object)a[i]);
338-
Vector3 bV = (Vector3)((object)b[i]);
339-
for (int j = 0; j < 3; j++)
340-
{
341-
bResult &= aV[j].ApproximatelyEquals(bV[j]);
342-
}
328+
HEU_Logger.Log(aF + " " + bF);
343329
}
344-
else if (a[i].GetType() == typeof(Vector4))
330+
}
331+
else if (a[i].GetType() == typeof(Vector2))
332+
{
333+
Vector2 aV = (Vector2)((object)a[i]);
334+
Vector2 bV = (Vector2)((object)b[i]);
335+
for (int j = 0; j < 2; j++)
345336
{
346-
Vector4 aV = (Vector4)((object)a[i]);
347-
Vector4 bV = (Vector4)((object)b[i]);
348-
for (int j = 0; j < 4; j++)
349-
{
350-
bResult &= aV[j].ApproximatelyEquals(bV[j]);
351-
}
337+
bResult &= aV[j].ApproximatelyEquals(bV[j]);
352338
}
353-
else if (a[i].GetType() == typeof(Matrix4x4))
339+
}
340+
else if (a[i].GetType() == typeof(Vector3))
341+
{
342+
Vector3 aV = (Vector3)((object)a[i]);
343+
Vector3 bV = (Vector3)((object)b[i]);
344+
for (int j = 0; j < 3; j++)
354345
{
355-
Matrix4x4 aV = (Matrix4x4)((object)a[i]);
356-
Matrix4x4 bV = (Matrix4x4)((object)b[i]);
357-
for (int j = 0; j < 16; j++)
358-
{
359-
bResult &= aV[j].ApproximatelyEquals(bV[j]);
360-
}
346+
bResult &= aV[j].ApproximatelyEquals(bV[j]);
361347
}
362-
else if (a[i].GetType() == typeof(Color))
348+
}
349+
else if (a[i].GetType() == typeof(Vector4))
350+
{
351+
Vector4 aV = (Vector4)((object)a[i]);
352+
Vector4 bV = (Vector4)((object)b[i]);
353+
for (int j = 0; j < 4; j++)
363354
{
364-
Color aV = (Color)((object)a[i]);
365-
Color bV = (Color)((object)b[i]);
366-
bResult &= aV.r.ApproximatelyEquals(bV.r);
367-
bResult &= aV.g.ApproximatelyEquals(bV.g);
368-
bResult &= aV.b.ApproximatelyEquals(bV.b);
369-
bResult &= aV.a.ApproximatelyEquals(bV.a);
355+
bResult &= aV[j].ApproximatelyEquals(bV[j]);
370356
}
371-
else
357+
}
358+
else if (a[i].GetType() == typeof(Matrix4x4))
359+
{
360+
Matrix4x4 aV = (Matrix4x4)((object)a[i]);
361+
Matrix4x4 bV = (Matrix4x4)((object)b[i]);
362+
for (int j = 0; j < 16; j++)
372363
{
373-
bResult &= a[i].Equals(b[i]);
364+
bResult &= aV[j].ApproximatelyEquals(bV[j]);
374365
}
375366
}
367+
else if (a[i].GetType() == typeof(Color))
368+
{
369+
Color aV = (Color)((object)a[i]);
370+
Color bV = (Color)((object)b[i]);
371+
bResult &= aV.r.ApproximatelyEquals(bV.r);
372+
bResult &= aV.g.ApproximatelyEquals(bV.g);
373+
bResult &= aV.b.ApproximatelyEquals(bV.b);
374+
bResult &= aV.a.ApproximatelyEquals(bV.a);
375+
}
376+
else
377+
{
378+
bResult &= a[i].Equals(b[i]);
379+
}
376380

377-
PrintTestLogAndSetResult(bResult, ref result, header, subject, optional1, optional2, optional3);
381+
if (bResult == false && errorCount < 10)
382+
{
383+
string errorString = string.Format("mismatch on {0} : a {1} b {2}", i, a[i].ToString(), b[i].ToString());
384+
HEU_Logger.LogError(errorString);
385+
errorCount++;
386+
387+
}
388+
bTotalResult &= bResult;
378389
}
379390

380-
return bResult;
391+
PrintTestLogAndSetResult(bTotalResult, ref result, header, subject, optional1, optional2, optional3);
392+
393+
return bTotalResult;
381394
}
382395

383396
public static bool AssertTrueLogEquivalent(string[] a, string[] b, ref bool result, string header,

0 commit comments

Comments
 (0)