Revolutionary-Games / Thrive

The main repository for the development of the evolution game Thrive.
https://revolutionarygamesstudio.com/
Other
2.78k stars 495 forks source link

Save reading can randomly start failing after playing some time #5070

Open Teashrock opened 4 months ago

Teashrock commented 4 months ago

Describe the bug

I was playing the latest stable version of Thrive, 0.6.6. In my playthrough, autosave is enabled. While playing, I had to delete saves where my species appeared in an unsuitable environment. And, after I deleted a save, I loaded the one where the cell editor is opened. But then the thing: one time, the save refused to load, giving me an error. I thought it was a glitch and tried again, but the error persisted. Then, I saved the error log and came here. After I restarted the game, the save loaded as usual.

To Reproduce

  1. Open Thrive.
  2. Make sure autosave is enabled.
  3. Load the save where the cell editor opened and continue playing.
  4. Play some time.
  5. Delete a save where the playthrough has failed.
  6. Load the cell editor save to try a different approach.
  7. Repeat steps from 4 to 6 until the loading crashed at "Reading save data".

Expected behaviour

  1. I delete any save file.
  2. I load any save file.
  3. No errors happening ever.

Screenshots

No response

System information

Game Logs

https://pastebin.com/n8tNw3pH

Additional Context

After I restarted the game, the save loaded as usual, so it's a loading mechanism bug. Here's the link to the save file to explore further: https://www.mediafire.com/file/nt5g17adqmh2qmt/auto_save_1.thrivesave/file

hhyyrylainen commented 4 months ago

I think your save file has data that cannot be correctly loaded for some reason.

For reference this is the error:

Newtonsoft.Json.JsonException: Scene loaded JSON deserialized type can't be assigned to target type
   at BaseThriveConverter.CreateDeserializedFromScene(Type objectType, InProgressObjectDeserialization objectLoad) in /home/hhyyrylainen/Projects/Thrive/src/saving/serializers/ThriveJsonConverter.cs:line 432
   at InProgressObjectDeserialization.CreateInstance() in /home/hhyyrylainen/Projects/Thrive/src/saving/serializers/InProgressObjectDeserialization.cs:line 389

Meaning that the game was able to read the save file but the data structure ends up it trying to do an invalid data assignment after loading one part of the save.

Loading the provided save file works for me without any errors. Could you verify that that is the save file that doesn't work for you?

Edit: alternatively if there exists a JSON debug log file in the game logs folder, you could provide that as it has quite good information for me to investigate further.

Teashrock commented 4 months ago

@hhyyrylainen Like I said, this bug happens suddenly after the save was loaded successfully multiple times. Since some point, it just fails to load the save. Restarting the game is what helps, making it load the save successfully (again). The save itself is valid. It's just a bug in the loading mechanism or whatever else, I may be mistaken.

hhyyrylainen commented 4 months ago

I see. I've tried loading the save multiple times but I didn't see any problems. The one thing that could theoretically cause this is that the save file read closes early leaving part of the data unread, but I would suspect more that that would fail with JSON parse error. I can try double checking save file reading to make sure it should read the entire file. Have you seen a similar error in the museum page? That has exact same file loading code as the saving system.

Teashrock commented 4 months ago

@hhyyrylainen

I've tried loading the save multiple times but I didn't see any problems.

I don't think it's easy to reproduce, as it happens occasionally. I don't even know the frequency of the bug, as it's the first time ever me encountering it. All I can assume is me trying to load the save too quickly after it was loaded.

Have you seen a similar error in the museum page? That has exact same file loading code as the saving system.

No. How can I check for it?

hhyyrylainen commented 4 months ago

Open the thriveopedia and go to the museum page. Things work correctly if you see cells there (of course you need to have fossilized some for them to appear at all) and can click on one to see the properties:

2024-04-28_13 57 42 6764

Teashrock commented 4 months ago

@hhyyrylainen I checked, it loads normally. I think I should do it multiple times to do it. Or maybe, it's some in-game thing. Like I said, I can assume it's me trying to load the save too quickly after it was loaded.

Teashrock commented 4 months ago

Just happened again. Here's the log: https://pastebin.com/WT4BxMW8 It seems it's not too difficult to reproduce. I think I understand what can be causing this: I mistakenly confirmed the cell in the editor without any changes, so the game continued. I opened the menu immediately when the game loaded, then deleted the autosave and loaded the editor one. And the crash happened!

It seems the bug has some relation to the time that passes after a non-editor save is loaded. Maybe some background process doesn't manage to initialize something or free some data before I pause the game and load anything?

UPD: Save file here: https://www.mediafire.com/file/xomxym90ust04v2/auto_save_1%25282%2529.thrivesave/file

UPD: Strange, this time the save loaded normally after just exiting to main menu. No restart was needed.

hhyyrylainen commented 4 months ago

I'd really love to see the json_debug.txt file content. This second error seems very different:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at EditorBase`2.set_EditorReady(Boolean value) in /home/hhyyrylainen/Projects/Thrive/src/general/base_stage/EditorBase.cs:line 181
   at InvokeStub_EditorBase`2.set_EditorReady(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at BaseThriveConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in /home/hhyyrylainen/Projects/Thrive/src/saving/serializers/ThriveJsonConverter.cs:line 594

That shouldn't able to be any kind of save data reading bug. This looks more like a rare bug in the Godot engine where it has incorrectly loaded a scene with not all of its resources. The game log file from when that error occurred might have errors from the engine that are related to the save load problem.

I had kind of similar problem where the Godot engine refused to consistently load about 3 NodePath variables. Switching those to use direct node references fixed those cases. We have not switched all of our code to use those direct references yet as it is a lot of work, but if this is done it might also fix the save load problem: https://github.com/Revolutionary-Games/Thrive/issues/4940

Teashrock commented 4 months ago

Ok, The current json_debug.txt is unrelated, as I played further already, but I'll attach it if I encounter the bug again. Also, if it's really that Godot bug, then I just have to wait until it's fixed.