ClientSim icon indicating copy to clipboard operation
ClientSim copied to clipboard

InvalidOperationException: Collection was modified; enumeration operation may not execute.

Open FairplexVR opened this issue 1 year ago • 1 comments

This error message appears in the console when removing a remote player with ClientSim. The spawned remote player remains in the hierarchy and is not properly destroyed.

Screenshot_1

Afaik, it started happening since ClientSim 1.2.4

FairplexVR avatar Jul 22 '23 06:07 FairplexVR

After doing some researches, it seems that the culprit loop can be found in UdonManager at line 871

I added an explicit ToList() as a workaround

public void RunEvent(string eventName, params (string symbolName, object value)[] eventParameters)
{
    foreach (Dictionary<GameObject, HashSet<UdonBehaviour>> sceneUdonBehaviourDirectory in
        _sceneUdonBehaviourDirectories.Values)
    {
        foreach (HashSet<UdonBehaviour> udonBehaviourList in sceneUdonBehaviourDirectory.Values.ToList())
        {
            foreach (UdonBehaviour udonBehaviour in udonBehaviourList)
            {
                if (udonBehaviour != null)
                {
                    udonBehaviour.RunEvent(eventName, eventParameters);
                }
            }
        }
    }
}

FairplexVR avatar Oct 13 '23 11:10 FairplexVR