Forum rules - please read before posting.

SaveGame XML Serialization Bug and solution

Hi @ChrisIceBox ,
SaveGame (xml serialization) system used on iOS, WII, PS4 is potentially bugged since it could produce broken/not readable xml files.
There are cases where the conversion from memory stream to string creates illegal characters.
I experienced it myself and made a temporary fix adding an additional Base64Encoding pass.
Can you please consider to apply this fix for the next patch version?
thx

Comments

  • edited December 2019

    What temporary fix have you made?

  • edited December 2019

    since you cannot directly represent a memorystream as xml string without any potential issues you have to add:

    Serialize (just before return)-> System.Convert.ToBase64String(memoryStream.ToArray());

    Deserialize(at first)->bytes=System.Convert.FromBase64String(dataString);
    dataString=System.Text.Encoding.UTF8.GetString(bytes);

    then you have to handle the way you recognize the file content (dataString.Contains etc..)

    this is what I had to do to avoid illegal characters inside xml

  • Thanks for the clarification - will look into it.

  • I've no doubt you're onto something here, but such a conversion invalidates existing save files.

    I'm hesistant to make such a change without an example of a specific scenario that causes problems. Can you provide steps to recreate an actual issue?

    If you're looking for peace of mind, do know that you can implement your change as a custom save format. Copy your modified script into a new class (e.g. FileFormatHandler_Xml_Encoded), and you can then rely on that instead of the default with the following in a script in your game's first AC scene:

    private void OnEnable ()
    {
        SaveSystem.FileFormatHandler = (iFileFormatHandler) new FileFormatHandler_Xml_Encoded ();
    }
    
  • edited December 2019

    It happened to me as well.

    To avoid breaking saves in new projects, may I suggest letting the user choose to keep using the old (breakable) XML serialization shipped with AC, and the new, safer, version, calling the former one "legacy XML"?

  • Did it happen with saves created with v1.69.5?

  • Yup, with slight alterations to the code, got in touch with flag74 to solve the issue (iOS/XML only).

    Is there a reason we have to use XML for iOS? Pretty sure there is, but I'm not sure.
    Size limitation on the playerprefs?

  • XML is a save format. PlayerPrefs is a save location. You can save to PlayerPrefs on iOS if you choose to - see the Manual's "Custom save formats and handling" chapter.

    As I've said, I'm reluctant to make such a change without steps to recreate the issue myself. However, it may be possible to use a try/catch statement to keep old saves compatible.

    Try this:
    https://paste.ofcode.org/jaDSAEnk6yTw2Pk7yxk85r

  • So, there is no technical limitation on iOS to just save everything on the playerprefs as a string?

    I got a bit confused because if I read it right, on iOS XML serialization is the preferred saving method in AC.

  • No - iOS can save data to PlayerPrefs. The data it saves, however, still needs to be serialized. This can be in XML or Json formats, and is separate from where the data is actually stored.

    Please try the link above, as I will require feedback from it before I can consider official inclusion.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.