Skip to content

Commit 9154152

Browse files
GravxdTomGrobbe
andauthored
Fixing a JSON crash on saved weapon loadout data (#551)
* fix(menus/weaponLoadouts) ensuring broken/corrupted JSON doesnt crash the menu building * Update WeaponLoadouts.cs * Update WeaponLoadouts.cs --------- Co-authored-by: Tom <31419184+TomGrobbe@users.noreply.github.com>
1 parent 6cd2bd2 commit 9154152

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

vMenu/menus/WeaponLoadouts.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
using CitizenFX.Core;
45

@@ -71,7 +72,18 @@ private Dictionary<string, List<ValidWeapon>> RefreshSavedWeaponsList()
7172

7273
foreach (var save in saves)
7374
{
74-
SavedWeapons.Add(save, JsonConvert.DeserializeObject<List<ValidWeapon>>(GetResourceKvpString(save)));
75+
var kvpValue = GetResourceKvpString(save);
76+
if (!string.IsNullOrEmpty(kvpValue))
77+
{
78+
try
79+
{
80+
SavedWeapons.Add(save, JsonConvert.DeserializeObject<List<ValidWeapon>>(kvpValue));
81+
}
82+
catch (Exception ex)
83+
{
84+
Debug.WriteLine($"[vMenu] Error: Failed to load corrupted saved loadout.\nStacktrace: {ex.StackTrace}\nError message: {ex.Message}\nSaved JSON: {kvpValue}\nSaveName: {save}");
85+
}
86+
}
7587
}
7688

7789
return SavedWeapons;

0 commit comments

Comments
 (0)