Incorrect exception

Discussion and help for Easy Save 3
Post Reply
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Incorrect exception

Post by Gladyon »

In the 'ES3Reader' class, the 'T Read<T>(ES3Type type)' and 'void ReadInto<T>(object obj, ES3Type type)' can (and do if there's an unknown type) throw an incorrect exception.
Here is the culprit:
if(type == null)
	throw new NotSupportedException("Type of "+type.type.ToString()+" is not currently supported, and could not be loaded using reflection.");
Obviously that exception is never thrown as it generate a null reference exception as 'type' is null.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Incorrect exception

Post by Joel »

Thanks for the heads-up, looks like we've refactored a part of our code but haven't propagated the changes to the body of the exception (it's meant to output the type of the generic parameter). I'll get this fixed in the next update.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Re: Incorrect exception

Post by Gladyon »

We all do these mistakes, and it's not that important.
It's just that I happened to see it.

But the context in which that exception occurred is troubling me a bit.
I had some data saved using a structure, and I changed the name of the structure in my code.
Then, when I tried to load the data again, I couldn't.

Is there a way to modify/rename a structure without losing the ability to read the data?
Of course I understand that if the changes are too extensive it cannot work, but in this case it was just the name, not the fields or the structure of the data.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Incorrect exception

Post by Joel »

The reason the data would have become unreadable is because for testing reasons during the beta, we're writing the buffer to file regardless of whether an exception occurred (essentially corrupting the data). This is so that we can see from the save file at which point during the save process something failed.

When it comes to release, data will only be written to the file if an exception does not occur.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Re: Incorrect exception

Post by Gladyon »

I'm not sure I've explained myself correctly, sorry.
What I meant is that I have a struct that I am using to save my data.
Here is the data written in the .json file:
"InGameMenu": {
    "__type": "UI.SavedActionKey,Assembly-CSharp",
    "value": {
        "Name": "InGameMenu",
        "Key1": {
            "Key": 27,
            "IsCtrl": false,
            "IsAlt": false,
            "IsShift": false
        },
        "Key2": {
            "Key": 0,
            "IsCtrl": false,
            "IsAlt": false,
            "IsShift": false
        }
    }
},
As you can see, my struct is called 'SavedActionKey'.
If I rename it in my code to 'SavedAction' for example, then I recompile, and then I launch my game, when it will attempt to load the data the exception I had will occur.
What I have to do is either to rename the type in the file, or to clear it and save it again with the new struct name.

For now it's not a problem for me as I'm still in development, but that would prevent any renaming in a released game.

I understand that you use the name of the type to identify it, but I was just asking if there was a way to read the data anyway as long as the format is compatible.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Incorrect exception

Post by Joel »

Ahh I understand now.

There's an undocumented field in the ES3Settings class called typeChecking which you can use to enable and disable type checking.

For example:
var settings = new ES3Settings();
settings.typeChecking = false;
var value = ES3.Load<SavedAction>("myKey", settings);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Re: Incorrect exception

Post by Gladyon »

Joel wrote:Ahh I understand now.

There's an undocumented field in the ES3Settings class called typeChecking which you can use to enable and disable type checking.

For example:
var settings = new ES3Settings();
settings.typeChecking = false;
var value = ES3.Load<SavedAction>("myKey", settings);
All the best,
Joel

Thanks for the information.
I'm currently using ES3file, and it doesn't seem to work with it.
I open the file using that instruction:
ES3File ConfigurationFile = new ES3File(FileName, QGlobal.ES3_SETTINGS, true);
Where:
ES3_SETTINGS = new ES3Settings(true);
ES3_SETTINGS.typeChecking = false;
And I load the data with:
AllActions[ActionNb] = ConfigurationFile.Load(CurrentAction.Value.FullId, new SavedActionKey());
I've not tracked the entire code, but 'typeChecking ' seems not to be used in ES3File.
As it is a undocumented feature from a beta version I understand totally that it's not yet fully functional.
Knowing that some day it will be implemented is enough for me.


By the way, for a new Easy Save user like me it's not very clear what are the advantages of ES3file over ES3.Load, and the opposite.
In fact, I'm using ES3File as I want to load a configuration file and update it when the user changes the configuration, but maybe it's not the best way to do it.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Incorrect exception

Post by Joel »

Hi there,

Type checking can't currently be disabled with ES3File because the ES3Type used to load the data is cached to improve performance. However, if you wish I can send you a version for which type checking can be disabled?

The performance benefits of ES3File can be found at the top of the ES3File guide. Note that if you're only saving a basic configuration file the ES3.Save and ES3.Load methods should be fine.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Re: Incorrect exception

Post by Gladyon »

Joel wrote: Type checking can't currently be disabled with ES3File because the ES3Type used to load the data is cached to improve performance. However, if you wish I can send you a version for which type checking can be disabled?
That's what I saw in the code.
If it's not too much a problem, that would be good to be able to disable the type checking also for ES3file.
I'm not sure how much it would impact the performances but I think that the features of ES3.Load and ES3File should be the most similar as possible.
It's less confusing for the user and provides more features.
Joel wrote: The performance benefits of ES3File can be found at the top of the ES3File guide. Note that if you're only saving a basic configuration file the ES3.Save and ES3.Load methods should be fine.
Joel
Thanks for the link, I thought that ES3File were more efficient.
I know that it's an overkill for a simple configuration file, but I'd like to have only one saving system in the whole project, it's easier to maintain.
That's why being able to disable type checking for ES3File when using configuration file is very interesting. That makes it possible to have one syntax only to save configuration and game data, configuration not optimized but more flexible, while game data load/save is optimized.


I really think that the power of ES3 is in its sheer number of features. Whatever you want to do, if it's related to loading/saving then Easy Save can do it.
Keep up the good work!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Incorrect exception

Post by Joel »

No problem, I'll PM you over an updated ES3File.cs.

I think you're right regarding keeping it consistent, so these changes will likely be pushed into a future update.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply