We got this error while trying to save a PlayerObject.
- Code: Select all
Collection was modified; enumeration operation may not execute.
First seen 13 hours ago, latest one hour ago. (Delete 1 error)
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at Game.players.Player.Save()
at Game.data.SaveManager.b__0(Player p)
at Game.data.SaveManager.Update()
at Game.GameRoom.b__6()
We try to save our PlayerObjects once every second. The save will go through if the playerObject is dirty and no save is currently going on.
Now, do we have to lock the playerObject to avoid this error?
Here is the current code:
- Code: Select all
public void Save()
{
if (!isSaving && dirty)
{
isSaving = true;
PlayerObject.Save(false, false, OnSaveComplete, OnSaveError);
}
}
private void OnSaveComplete()
{
isSaving = false;
dirty = false;
}
private void OnSaveError(PlayerIOError error)
{
isSaving = false;
dirty = true;
g.PlayerIO.ErrorLog.WriteError("Warning: OnSaveError: " + error.Message);
}