blish-hud / Blish-HUD

A Guild Wars 2 overlay with extreme extensibility through compiled modules.
https://blishhud.com
MIT License
331 stars 61 forks source link

Persistent data can be null (but it should never be) - crash on launch #95

Closed dlamkins closed 3 years ago

dlamkins commented 5 years ago

https://github.com/blish-hud/Blish-HUD/blob/d185ad629d57812c3f00a241b883db4fca7a330e/Blish%20HUD/GameServices/PersistentStore/Store.cs#L42

Newtonsoft.Json.JsonReaderException
  HResult=0x80131500
  Message=Error reading JObject from JsonReader. Current JsonReader item is not an object: Null. Path '', line 1, position 4.
  Source=Newtonsoft.Json
  StackTrace:
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Blish_HUD.PersistentStore.Store.PersistentStoreConverter.ReadJson(JsonReader reader, Type objectType, Store existingValue, Boolean hasExistingValue, JsonSerializer serializer) in C:\Projects\BlishHUD\Blish HUD\GameServices\PersistentStore\Store.cs:line 42
   at Newtonsoft.Json.JsonConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)

It appears that something is allowing the persistent.json to be set to null. Something should be put in place to prevent this from happening as it causes the application to crash when it first starts loading and tries to read in the current persistent data.

dlamkins commented 5 years ago

Another user is now experiencing this problem: https://discordapp.com/channels/531175899588984842/534492012263636992/614441543234748419

I'll want to try and replicate it before putting in a fix to ensure we nail the reason for why it is happening. Three theories at the moment:

Theory 1: The persistent data structure is of an old format (from a previous build), fails to deserialize, and then gets re-serialized as null and saved.

Theory 2: For systems that don't have persistent data generated yet, the initial serialization is null and then gets saved as null.

Theory 3: Something in the PersistentStoreConverter (https://github.com/blish-hud/Blish-HUD/blob/348f8e961f78381459e2e754bd1b116d2e6990b7/Blish%20HUD/GameServices/PersistentStore/Store.cs#L12) is soft-failing and causing it to serialize null.

dlamkins commented 4 years ago

The service is able to gracefully recover now, but still leaves a nasty stack trace anytime it comes up. "Theory 2" I believe is officially the root cause here.

https://discordapp.com/channels/531175899588984842/534492012263636992/692426231827923014

We can see it recover: 18:23:42.9144|WARN|Blish_HUD.PersistentStoreService|Persistent store could not be read, so a new one will be generated.

Probably a better solution would just to not have it right null to the file to begin with, though so that folks don't get this on fresh launch.

dlamkins commented 3 years ago

Hasn't been an issue for quite some time as far as I can tell.