MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

if, integer comparisons fail #39

Closed MolotovCherry closed 4 years ago

MolotovCherry commented 4 years ago

I'm comparing the length of a string in an if statement,

string foo = "foo";
if (foo.Length < 7} {}

While this compiles and runs, the moment the method with this code is invoked, this pops up.

[<color=yellow>UdonBehaviour</color>] An exception occurred during Udon execution, this UdonBehaviour will be halted.
VRC.Udon.VM.UdonVMException: The VM encountered an error!

[<color=#FF00FF>UdonSharp</color>] Myscript.cs: Udon runtime exception detected!
  An exception occurred during EXTERN to 'SystemString.__get_Length__SystemInt32'.

Edit: So private strings are initialized to null? Can we put something in the documentation warning of the behavior?

MerlinVR commented 4 years ago

(from discussion on Discord https://discordapp.com/channels/652715801714884620/675466846127915019/715757603862609939) Example code is incomplete and hiding a user error where string fields are defined to be null. This is defined Unity behavior in C# and should not need to be documented here, thanks!

MolotovCherry commented 4 years ago

Yup. Thanks for the help. My bad as I'm new xD. Appreciate your project! ;)