Search Unity

what does "snapshot out of sync" mean?

Discussion in 'Scripting' started by ilcygnet, Sep 10, 2009.

  1. ilcygnet

    ilcygnet

    Joined:
    Sep 10, 2009
    Posts:
    28
    hi i'm developing web game with ur Unity3d and SmartFoxServer technology.
    as u provided nice example, it's very comfortable to understand co-operation of both server and client.

    but here i have a problem with my code.
    plz read debug message below:

    Code (csharp):
    1. InvalidOperationException: Hashtable.Enumerator: snapshot out of sync.
    2. System.Collections.Hashtable+Enumerator.FailFast ()
    3. System.Collections.Hashtable+Enumerator.MoveNext ()
    4. LobbyGUI.SetupRoomList ()   (at Assets\Game\Scripts\LobbyGUI.cs:206)
    5. LobbyGUI.Awake ()   (at Assets\Game\Scripts\LobbyGUI.cs:66)
    this exception happens when i typed username and press submit button in login user interface.
    and strangely this exception happens often, not always.

    and the code LobbyGUI.cs:66 is like this:

    Code (csharp):
    1.     private void SetupRoomList() { 
    2.         List<string> rooms = new List<string>();
    3.  
    4.         foreach ( Room room in smartFox.GetAllRooms().Values ) {
    5.  
    6.             // Only show game rooms
    7.             if ( !room.IsGame()) {
    8.                 continue;
    9.             }
    10.  
    11.             Debug.Log("Room id: " + room.GetId() + " has name: " + room.GetName());
    12.  
    13.             rooms.Add(room.GetName());
    14.         } //////////// this is line 66
    15.  
    16.         roomStrings = rooms.ToArray();
    17.     }
    this code is totally from example except i transported it to my own project.
    i cannot understand why this exception happens and even i don't know what "snapshot out of sync" means.

    plz someone tell me how i can solve these problem.
    i cannot go any further by the virtue of this bug thx...
     
  2. jmunozar

    jmunozar

    Joined:
    Jun 23, 2008
    Posts:
    1,091
    Just a thought,

    Are you managing the exceptions when your client cannot connect to your server?, are you managing timeouts from the server?

    as I told you its just a thought as I'm not an expert in smartfox :(, but this might be a reason of that problem you are having, as it happens often :)
     
  3. ilcygnet

    ilcygnet

    Joined:
    Sep 10, 2009
    Posts:
    28
    well connection to the server is established in the previous step of writing username and password.
    because smartFox.IsConnected() is true in login interface, so i think it's totally safe to proceed
    from connection step to login step.

    but the connection status can be a problem as u said i will check it up again. smartFox.GetAllRooms() may throw exception :)

    thank you!
     
  4. jkalkhof

    jkalkhof

    Joined:
    Sep 16, 2008
    Posts:
    26
    I ran into the same problem using two functions
    one was an iterator through a hashtable.
    The sub function was trying to save data in the hashtable.
    Code (csharp):
    1.  
    2. function a() {
    3.     for ( var name_str : String in myhash.Keys ) {
    4.            
    5.             result_str = dostuff(name_str);
    6.            
    7.     }
    8. }
    9.  
    10. function dostuff(name_str : String) {
    11.     var result_str = myhash[name_str]
    12.  
    13.     myhash[name_str] = "try this";
    14.  
    15.     return result_str;
    16. }
    the solution that worked for me was:
    don't store data in the hashtable while I was iterating through it
     
  5. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    I'm getting the same thing but all I'm doing is reading from a SortedList

    Code (csharp):
    1. for (var key in globals.hidden.list.Keys) {
    2.             globals.hidden.list[key].active = false;
    3.         }
    4.  
    Oddly too this has only been a problem since moving to Unity 3 from 2.6