Forum BigDB PlayerIOClient.PlayerIOError: CircularReference

Discussion and help relating to the PlayerIO database solution, BigDB.

PlayerIOClient.PlayerIOError: CircularReference

Postby lionlab » April 2nd, 2015, 9:35 am

Hello! Unity 4.6.3f1, Lang C#, SDK v 3.2.0. Platform - Web.
Help me please. One question - where the Circular Reference? In code:
Code: Select all
client.BigDB.LoadOrCreate ("Users", "21343246457647568", delegate (DatabaseObject result) {
         if (result.Contains ("MyList")) {
            result.Set ("DateLastVisit",MainControl.ServerDateTime);
            MainControl.MyList = result.GetArray ("MyList"); //DatabaseArray MyList = new DatabaseArray();
            result.Save();
}
});
.....
client.BigDB.Load ("Users", "21343246457647568", delegate (DatabaseObject result) {
         if (result != null) {
            if (MainControl.MyList.Count>0)
            result.Set("MyList",MainControl.MyList); //Debugger here get error
            result.Save(null);
         }
         if (result == null)Debug.Log ("Error");
      });
         }

Unity error on run application:
PlayerIOClient.PlayerIOError: CircularReference; Cannot create circular references inside database objects
at PlayerIOClient.Internal.identifier919[K].Set (.K key, PlayerIOClient.Internal.identifier923 value) [0x00000] in <filename unknown>:0
lionlab
 
Posts: 5
Joined: March 12th, 2015, 3:06 pm

Re: PlayerIOClient.PlayerIOError: CircularReference

Postby Henrik » April 3rd, 2015, 5:08 am

You can't put a part of a DatabaseObject onto another DatabaseObject. Your "MyList" object knows that it belongs to another, and throws the error. You have to create a new DatabaseArray on the other DatabaseObject, and copy over the values one by one.
Henrik
.IO
 
Posts: 1832
Joined: January 4th, 2010, 1:53 pm

Re: PlayerIOClient.PlayerIOError: CircularReference

Postby Yonom » April 5th, 2015, 10:44 pm

I recently stumbled upon this issue. I think it would be nice if you had a .Clone() method on database objects. That would save a lot of time. :D

Oh and here is how I implemented my own Clone method:

Code: Select all
    static class Utils
    { 
        public static DatabaseObject Clone(this DatabaseObject obj)
        {
            var clone = new DatabaseObject();
            foreach (var item in obj)
            {
                var databaseObj = item.Value as DatabaseObject;
                if (databaseObj != null)
                {
                    clone.Set(item.Key, databaseObj.Clone());
                }
                else
                {
                    var databaseArray = item.Value as DatabaseArray;
                    if (databaseArray != null)
                    {
                        clone.Set(item.Key, databaseArray.Clone());
                    }
                    else
                    {
                        clone.Set(item.Key, (dynamic)item.Value);
                    }
                }
            }
            return clone;
        }

        public static DatabaseArray Clone(this DatabaseArray obj)
        {
            var clone = new DatabaseArray();
            foreach (var item in obj)
            {
                var databaseObj = item as DatabaseObject;
                if (databaseObj != null)
                {
                    clone.Add(databaseObj.Clone());
                }
                else
                {
                    var databaseArray = item as DatabaseArray;
                    if (databaseArray != null)
                    {
                        clone.Add(databaseArray.Clone());
                    }
                    else
                    {
                        clone.Add((dynamic)item);
                    }
                }
            }
            return clone;
        }
    }
Yonom
 
Posts: 4
Joined: March 30th, 2012, 8:11 pm


Return to BigDB



cron