From a29cf46dd309610167d67a1d0d3415133bded642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=86=E3=82=8C=E3=81=84=E3=81=97?= <57707826+ureishi@users.noreply.github.com> Date: Mon, 25 Dec 2023 17:27:53 +0900 Subject: [PATCH] fix enum cast --- .../Editor/Compiler/Emit/EmitContext.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Emit/EmitContext.cs b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Emit/EmitContext.cs index 961849d7..0d1e106d 100644 --- a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Emit/EmitContext.cs +++ b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Emit/EmitContext.cs @@ -448,16 +448,16 @@ private Value GetEnumArrayForType(Type enumType) maxEnumVal = (int)enumVal > maxEnumVal ? (int)enumVal : maxEnumVal; // After a survey of what enums are exposed by Udon, it doesn't seem like anything goes above this limit. The only things I see that go past this are some System.Reflection enums which are unlikely to ever be exposed. - if (maxEnumVal > 2048) + if (maxEnumVal >= 2048) throw new System.NotSupportedException($"Cannot cast integer to enum {enumType.Name} because target enum has too many potential states({maxEnumVal}) to contain in an UdonBehaviour reasonably"); // Find the most significant bit of this enum so we can generate all combinations <= it int mostSignificantBit = 0; - int currentEnumVal = maxEnumVal; + int currentEnumValCount = maxEnumVal + 1; - while (currentEnumVal > 0) + while (currentEnumValCount > 0) { - currentEnumVal >>= 1; + currentEnumValCount >>= 1; ++mostSignificantBit; }