An error occurs in ClientSim when a synced VRCUrl variable is null in a PlayerObject with Persistence enabled.
tracked
kurotori
VRCSDK 3.7.5
Steps to Reproduce:
- Attach the VRC Enable Persistence component and VRC Player Object component to an object.
- Attach the following UdonSharp script to the same object.
- Execute Interact() in ClientSim.
---
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class VRCURLPersistenceTest : UdonSharpBehaviour
{
[UdonSynced]
private VRCUrl testUrl;
public override void Interact()
{
RequestSerialization();
}
}
---
Observed Error:
When running the script in ClientSim, the following NullReferenceException occurs:
---
NullReferenceException: Object reference not set to an instance of an object
VRC.SDK3.ClientSim.Editor.VisualElements.Fields.FieldFactory.GenerateField[T] (System.String fieldName, T data) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Editor/VisualElements/Fields/FieldFactory.cs:79)
VRC.SDK3.ClientSim.Editor.VisualElements.EncodeDecodeEditors.ClientSimUdonEncodeDecodeEditor.GenerateFields (UnityEngine.MonoBehaviour component, VRC.SDK3.Data.DataDictionary data) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Editor/VisualElements/EncodeDecodeEditors/ClientSimUdonEncodeDecodeEditor.cs:30)
VRC.SDK3.ClientSim.Editor.VisualElements.ClientSimNetworkHolderInstanceElement.GenerateDataElements (System.Int32 index) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Editor/VisualElements/ClientSimNetworkHolderInstanceElement.cs:72)
VRC.SDK3.ClientSim.Editor.VisualElements.ClientSimNetworkHolderInstanceElement.UpdateData (VRC.SDK3.ClientSim.Editor.ClientSimPlayerObjectWindow+PlayerObjectData data) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Editor/VisualElements/ClientSimNetworkHolderInstanceElement.cs:94)
VRC.SDK3.ClientSim.Editor.ClientSimPlayerObjectWindow.UpdateCurrentPage (VRC.SDK3.ClientSim.ClientSimOnPlayerObjectUpdateEndedEvent e) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Editor/Windows/ClientSimPlayerObjectWindow.cs:259)
VRC.SDK3.ClientSim.ClientSimEventDispatcher.SendEvent[T] (T clientSimEvent) (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/Events/ClientSimEventDispatcher.cs:62)
VRC.SDK3.ClientSim.Persistence.ClientSimPlayerObjectStorage.LateUpdate () (at ./Packages/com.vrchat.worlds/Integrations/ClientSim/Runtime/Player/PlayerPersistence/ClientSimPlayerObjectStorage.cs:172)
---
Workaround:
Setting an initial value for the synced VRCUrl variable prevents the error:
---
[UdonSynced]
private VRCUrl testUrl = VRCUrl.Empty;
---
Possible Cause & Suggestion:
It seems that ClientSim does not handle null values properly when processing synced variables. Adding proper null handling for synced variables, especially for VRCUrl, may help prevent this error.
Log In
CompuGeniusCode
Dexvoid It seems null VRCUrls can't actually be saved to persistence, so this error is technically valid in ClientSim, yet should be properly descriptive.
Dexvoid
Merged in a post:
ClientSim Decoder Doesn't Null-Guard String or VRCUrl
CompuGeniusCode
If a persistent string or VRCUrl (or array of them) is initialized with null (by default), ClientSim crashes trying to read
dataToken.String
.The problematic code is in
ClientSimUdonEncodeDecode.Get
where it attempts to read dataToken.String
without checking for null.This crashes with the error "InvalidOperationException: Attempted to access Null token as String"
The line can be fixed by changing it to:
dataToken.TokenType == TokenType.Null ? "" : dataToken.String
and
dataToken.TokenType == TokenType.Null ? VRCUrl.Empty : new VRCUrl(dataToken.String)
Dexvoid
updated the status to
tracked