Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix enum cast #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading