MerlinVR / UdonSharp

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

Null pointer when naming player variable "player" #122

Closed wardd64 closed 3 years ago

wardd64 commented 3 years ago

It seems when you use "player" as a variable name for a player API you get random null pointer exceptions.

private VRCPlayerApi player;

private void Start() {
  player = Networking.LocalPlayer;
}

private void Update() {
  Debug.Log(player.GetPosition()); //Null pointer
}

I managed to fix this on my end by simply renaming the variable to "localPlayer". A warning at least would be nice, spent a long time debugging this. Here's the error log:

2021.09.28 19:12:47 Error      -  [UdonBehaviour] An exception occurred during Udon execution, this UdonBehaviour will be halted.
VRC.Udon.VM.UdonVMException: The VM encountered an error!
Exception Message:
  An exception occurred during EXTERN to 'VRCSDKBaseVRCPlayerApi.__GetPosition__UnityEngineVector3'.
      Parameter Addresses: 0x00000011, 0x00000020

  Object reference not set to an instance of an object.
----------------------
Program Counter was at: 568
----------------------
Stack Dump:
  0: 0x0000003C
----------------------
Heap Dump:
  0x00000000: 5447389887889789541
  0x00000001: UFForceRegionUdon
  0x00000002: False
  0x00000003: False
  0x00000004: False
  0x00000005: True
  0x00000006: 0
  0x00000007: 0
  0x00000008: 0
  0x00000009: 0
  0x0000000A: 1
  0x0000000B: 3.25
  0x0000000C: (0.0, 1.0, 0.0)
  0x0000000D: True
  0x0000000E: 100
  0x0000000F: null
  0x00000010: VRC.SDKBase.VRCPlayerApi
  0x00000011: null
  0x00000012: PushRegion_1062 (UnityEngine.Transform)
  0x00000013: PushRegion_1062 (VRC.Udon.UdonBehaviour)
  0x00000014: False
  0x00000015: null
  0x00000016: null
  0x00000017: (0.0, 0.0, 0.0, 0.0)
  0x00000018: (0.0, 0.0, 0.0, 0.0)
  0x00000019: 0
  0x0000001A: 0
  0x0000001B: null
  0x0000001C: (0.0, 0.0, 0.0)
  0x0000001D: (0.0, 0.0, 0.0)
  0x0000001E: (0.0, 0.0, 0.0)
  0x0000001F: (0.0, 0.0, 0.0)
  0x00000020: (0.0, 0.0, 0.0)
  0x00000021: (0.0, 0.0, 0.0)
  0x00000022: (0.0, 0.0, 0.0)
  0x00000023: null
  0x00000024: VRC.SDKBase.VRCPlayerApi
  0x00000025: 2
  0x00000026: 1
  0x00000027: 0
  0x00000028: null
  0x00000029: 100
  0x0000002A: 0
  0x0000002B: 1
  0x0000002C: 2
  0x0000002D: null
  0x0000002E: TEST
  0x0000002F: BOOM
  0x00000030: force region shove: 
  0x00000031: Jump pad push: 
  0x00000032: UnityEngine.Collider
  0x00000033: UnityEngine.BoxCollider
  0x00000034: UnityEngine.SphereCollider
  0x00000035: 1680
  0x00000036: 1604
  0x00000037: 1296
  0x00000038: 1124
  0x00000039: 1056
  0x0000003A: 948
  0x0000003B: 148
  0x0000003C: 4294967295
  0x0000003D: False
  0x0000003E: False
  0x0000003F: False
  0x00000040: False
  0x00000041: True
  0x00000042: True
  0x00000043: False
  0x00000044: False
  0x00000045: False
  0x00000046: False
  0x00000047: False
  0x00000048: False
  0x00000049: False
  0x0000004A: False
  0x0000004B: False
  0x0000004C: False
  0x0000004D: False
  0x0000004E: False
  0x0000004F: False
  0x00000050: False
  0x00000051: False
  0x00000052: False
  0x00000053: False
  0x00000054: null
  0x00000055: 0
  0x00000056: 0
  0x00000057: (0.0, 0.0, 0.0, 0.0)
  0x00000058: 0
  0x00000059: 0
  0x0000005A: 0
  0x0000005B: 0
  0x0000005C: 0
  0x0000005D: 0
  0x0000005E: 0
  0x0000005F: 0
  0x00000060: 0
  0x00000061: 0
  0x00000062: 0
  0x00000063: 0
  0x00000064: 0
  0x00000065: 0
  0x00000066: TEST(8.6, -1.0, -90.4)
  0x00000067: (8.6, -1.0, -90.4)
  0x00000068: BOOM(8.6, -1.0, -90.4)
  0x00000069: (8.6, -1.0, -90.4)
  0x0000006A: null
  0x0000006B: null
  0x0000006C: null
  0x0000006D: null
  0x0000006E: null
  0x0000006F: 4294967295
  0x00000070: (0.0, 100.0, 0.0)
  0x00000071: (8.6, -1.0, -90.4)
  0x00000072: (8.6, -1.0, -90.4)
  0x00000073: (0.0, 0.0, 0.0)
  0x00000074: (0.0, 0.0, 0.0)
  0x00000075: (0.0, 0.0, 0.0)
  0x00000076: (0.0, 0.0, 0.0)
  0x00000077: (0.0, 0.0, 0.0)
  0x00000078: (0.0, 0.0, 0.0)
  0x00000079: (0.0, 0.0, 0.0)
  0x0000007A: (0.0, 0.0, 0.0)
  0x0000007B: (0.0, 0.0, 0.0)
  0x0000007C: (0.0, 0.0, 0.0)
  0x0000007D: VRCSDKBaseNetworking.__get_LocalPlayer__VRCSDKBaseVRCPlayerApi
  0x0000007E: SystemInt32.__op_Inequality__SystemInt32_SystemInt32__SystemBoolean
  0x0000007F: SystemInt32.__op_GreaterThan__SystemInt32_SystemInt32__SystemBoolean
  0x00000080: SystemBoolean.__op_UnaryNegation__SystemBoolean__SystemBoolean
  0x00000081: VRCSDKBaseVRCPlayerApi.__IsPlayerGrounded__SystemBoolean
  0x00000082: SystemBoolean.__op_ConditionalAnd__SystemBoolean_SystemBoolean__SystemBoolean
  0x00000083: UnityEngineDebug.__Log__SystemObject__SystemVoid
  0x00000084: VRCSDKBaseVRCPlayerApi.__GetPosition__UnityEngineVector3
  0x00000085: SystemInt32.__op_Equality__SystemInt32_SystemInt32__SystemBoolean
  0x00000086: VRCSDKBaseVRCPlayerApi.__GetVelocity__UnityEngineVector3
  0x00000087: UnityEngineVector3.__get_x__SystemSingle
  0x00000088: UnityEngineVector3.__get_z__SystemSingle
  0x00000089: UnityEngineVector3.__ctor__SystemSingle_SystemSingle_SystemSingle__UnityEngineVector3
  0x0000008A: VRCSDKBaseVRCPlayerApi.__SetVelocity__UnityEngineVector3__SystemVoid
  0x0000008B: UnityEngineVector3.__ToString__SystemString
  0x0000008C: SystemString.__op_Addition__SystemString_SystemString__SystemString
  0x0000008D: VRCSDKBaseVRCPlayerApi.__GetRotation__UnityEngineQuaternion
  0x0000008E: UnityEngineTime.__get_deltaTime__SystemSingle
  0x0000008F: UnityEngineVector3.__op_Multiply__SystemSingle_UnityEngineVector3__UnityEngineVector3
  0x00000090: UnityEngineVector3.__op_Addition__UnityEngineVector3_UnityEngineVector3__UnityEngineVector3
  0x00000091: VRCSDKBaseVRCPlayerApi.__TeleportTo__UnityEngineVector3_UnityEngineQuaternion__SystemVoid
  0x00000092: SystemSingle.__op_Multiplication__SystemSingle_SystemSingle__SystemSingle
  0x00000093: SystemSingle.__op_Subtraction__SystemSingle_SystemSingle__SystemSingle
  0x00000094: SystemSingle.__op_Division__SystemSingle_SystemSingle__SystemSingle
  0x00000095: UnityEngineTransform.__get_position__UnityEngineVector3
  0x00000096: UnityEngineVector3.__op_Subtraction__UnityEngineVector3_UnityEngineVector3__UnityEngineVector3
  0x00000097: UnityEngineVector3.__get_normalized__UnityEngineVector3
  0x00000098: UnityEngineComponent.__get_transform__UnityEngineTransform
  0x00000099: UnityEngineSphereCollider.__GetComponent__T
  0x0000009A: UnityEngineBoxCollider.__GetComponent__T
  0x0000009B: UnityEngineObject.__op_Inequality__UnityEngineObject_UnityEngineObject__SystemBoolean
  0x0000009C: UnityEngineVector3.__get_magnitude__SystemSingle
  0x0000009D: UnityEngineSphereCollider.__get_radius__SystemSingle
  0x0000009E: UnityEngineTransform.__get_rotation__UnityEngineQuaternion
  0x0000009F: UnityEngineQuaternion.__Inverse__UnityEngineQuaternion__UnityEngineQuaternion
  0x000000A0: UnityEngineQuaternion.__op_Multiply__UnityEngineQuaternion_UnityEngineVector3__UnityEngineVector3
  0x000000A1: UnityEngineVector3.__get_y__SystemSingle
  0x000000A2: UnityEngineBoxCollider.__get_size__UnityEngineVector3
  0x000000A3: VRCSDKBaseVRCPlayerApi.__get_isLocal__SystemBoolean
  0x000000A4: SystemBoolean.__op_LogicalOr__SystemBoolean_SystemBoolean__SystemBoolean
  0x000000A5: SystemBoolean.__op_LogicalAnd__SystemBoolean_SystemBoolean__SystemBoolean
  0x000000A6: UnityEngineCollider.__GetComponentsInChildren__TArray
  0x000000A7: UnityEngineColliderArray.__get_Length__SystemInt32
  0x000000A8: SystemInt32.__op_LessThan__SystemInt32_SystemInt32__SystemBoolean
  0x000000A9: SystemObjectArray.__Get__SystemInt32__SystemObject
  0x000000AA: UnityEngineCollider.__set_enabled__SystemBoolean__SystemVoid
  0x000000AB: SystemInt32.__op_Addition__SystemInt32_SystemInt32__SystemInt32
----------------------
Inner Exception:
 ---> VRC.Udon.VM.UdonVMException: An exception occurred during EXTERN to 'VRCSDKBaseVRCPlayerApi.__GetPosition__UnityEngineVector3'.
    Parameter Addresses: 0x00000011, 0x00000020
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
  at VRC.Udon.Wrapper.Modules.ExternVRCSDKBaseVRCPlayerApi.__GetPosition__UnityEngineVector3 (VRC.Udon.Common.Interfaces.IUdonHeap heap, System.UInt32[] parameterAddresses) [0x00000] in <00000000000000000000000000000000>:0 
  at PlatformSupport.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke (System.Object sender, PlatformSupport.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.VM.UdonVM.Interpret () [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.RunProgram (System.UInt32 entryPoint) [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.RunEvent (System.String eventName, System.ValueTuple`2[System.String,System.Object][] programVariables) [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.ManagedUpdate () [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonManager.Update () [0x00000] in <00000000000000000000000000000000>:0 
   --- End of inner exception stack trace ---
  at VRC.Udon.VM.UdonVM.Interpret () [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.RunProgram (System.UInt32 entryPoint) [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.RunEvent (System.String eventName, System.ValueTuple`2[System.String,System.Object][] programVariables) [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.ManagedUpdate () [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonManager.Update () [0x00000] in <00000000000000000000000000000000>:0 
   --- End of inner exception stack trace ---
  at VRC.Udon.VM.UdonVM.Interpret () [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.RunProgram (System.UInt32 entryPoint) [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.RunEvent (System.String eventName, System.ValueTuple`2[System.String,System.Object][] programVariables) [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonBehaviour.ManagedUpdate () [0x00000] in <00000000000000000000000000000000>:0 
  at VRC.Udon.UdonManager.Update () [0x00000] in <00000000000000000000000000000000>:0 
PhaxeNor commented 3 years ago

This is a issue on the VRCSDK side Relevant canny https://feedback.vrchat.com/vrchat-udon-closed-alpha-bugs/p/runevent-will-clear-incorrect-event-parameter-names

Rename player to something else and it will work