I have this code:
- Code: Select all
PlayerIO.BigDB.LoadOrCreate("WorldObjects", slot.id, delegate(DatabaseObject saveObject)
{
DatabaseArray chunks = null;
if (saveObject.Contains("chunks"))
{
chunks = saveObject.GetArray("chunks");
}
else
{
chunks = new DatabaseArray();
saveObject.Set("chunks", chunks);
}
chunks.Clear();
foreach (DatabaseObject chunkObject in slot.chunkObjects)
{
chunks.Add(chunkObject); //Circular reference error
}
saveObject.Set("name", slot.name);
saveObject.Set("creator", playerKey);
saveObject.Set("width", slot.width);
saveObject.Set("height", slot.height);
saveObject.Save(false, delegate()
{
callback(true);
}, delegate(PlayerIOError error)
{
callback(false);
});
}, delegate(PlayerIOError error)
{
callback(false);
});
This code runs perfectly the first time I run it in a server room, but if I run this a second time, it thinks there's a circular reference. I think it thinks there's a circular reference because in the 'slot.chunkObjects' list, some of those chunk objects are not modified from the last time this function is called. Therefore, when the chunk object is added again to a database array, it somehow thinks there's a circular reference. This is strange, because the database array is cleared before the new items are added to it - but that shouldn't even matter because it would be impossible for something in memory (objects in the slot.chunkObjects list) to have a reference to a 1) newly instantiated database array, or 2) an object I just loaded from the database.
Maybe I'm looking at this all wrong, and there's some obvious answer, if so, please share
I've spent quite a bit of time at this, any help would be appreciated.