Every save after first produces ES2InvalidDataException

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
an0maly
Posts: 3
Joined: Mon Mar 23, 2015 3:14 am

Every save after first produces ES2InvalidDataException

Post by an0maly »

The initial save (when the serialization file is first created) works fine without error. Loading also works perfectly fine. However, any subsequent saves fail, throwing an ES2InvalidDataException. The file itself is not updated due to the exception, it remains in its original state. Here is the stack trace:

Code: Select all

ES2InvalidDataException: Easy Save 2 Error: The file provided does not contain data that is readable by Easy Save. Please make sure that file was created by Easy Save.
ES2Reader.Next ()
ES2Reader.DeleteTags (ICollection`1 tags, .ES2Writer writer)
ES2Writer.Delete ()
ES2Writer.Save (Boolean checkForOverwrite)
ES2Writer.Save ()
FooBar.Save () (at Assets/Scriptz/FooBar.cs:29)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/UnityEvent.cs:110)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/UnityEvent.cs:576)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/UnityEvent.cs:718)
UnityEngine.Events.UnityEvent.Invoke () (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/UnityEvent_0.cs:53)
UnityEngine.UI.Button.Press () (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/ExecuteEvents.cs:52)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()
I'm currently testing with a very basic setup. Here is how it looks, in a nutshell:

Code: Select all

class Foo {
     string name;
     int id;
}

class Bar {
     Foo[,] fooArray;
}
And here is how the write() function looks:

Code: Select all

public override void Write(object obj, ES2Writer writer) {
	
	Bar data = (Bar) obj;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			writer.Write(data.fooArray[i, j].Name);
			writer.Write(data.fooArray[i, j].Id);
		}
	}
	writer.Save();  //ES2InvalidDataException being thrown here
}
I'm currently using v2.6.2
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Every save after first produces ES2InvalidDataException

Post by Joel »

Hi there,

As you're saving sequentially without tags, you need to change:
writer.Save();
To:
writer.Save(false);
All the best,
Joel
an0maly
Posts: 3
Joined: Mon Mar 23, 2015 3:14 am

Re: Every save after first produces ES2InvalidDataException

Post by an0maly »

Beautiful, must have overlooked that.

Thank you kindly.
Locked