Skip to content

Commit

Permalink
Merge pull request #406 from FFXIV-CombatReborn/crashfixes
Browse files Browse the repository at this point in the history
Enhance thread safety and readability; add error handling
  • Loading branch information
LTS-FFXIV authored Sep 24, 2024
2 parents 575c62c + 06fe16c commit 477a8d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
9 changes: 5 additions & 4 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Configuration;
using ECommons.DalamudServices;
using ECommons.ExcelServices;
using System.Collections.Concurrent;
using static RotationSolver.Basic.Configuration.ConfigTypes;

namespace RotationSolver.Basic.Configuration;
Expand Down Expand Up @@ -689,15 +690,15 @@ public const string
#endregion

[JobConfig]
private readonly Dictionary<uint, ActionConfig> _rotationActionConfig = [];
private readonly ConcurrentDictionary<uint, ActionConfig> _rotationActionConfig = new ConcurrentDictionary<uint, ActionConfig>();

[JobConfig]
private readonly Dictionary<uint, ItemConfig> _rotationItemConfig = [];
private readonly ConcurrentDictionary<uint, ItemConfig> _rotationItemConfig = new ConcurrentDictionary<uint, ItemConfig>();

[JobChoiceConfig]
private readonly Dictionary<string, string> _rotationConfigurations = [];
private readonly ConcurrentDictionary<string, string> _rotationConfigurations = new ConcurrentDictionary<string, string>();

public Dictionary<uint, string> DutyRotationChoice { get; set; } = [];
public ConcurrentDictionary<uint, string> DutyRotationChoice = new ConcurrentDictionary<uint, string>();

public void Save()
{
Expand Down
7 changes: 5 additions & 2 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,13 @@ public static unsafe IBattleChara[] FriendlyNPCMembers
}

// Filter and cast objects safely
return Svc.Objects
.Where(obj => obj != null && obj.ObjectKind == Dalamud.Game.ClientState.Objects.Enums.ObjectKind.BattleNpc && (obj.GetNameplateKind() == NameplateKind.FriendlyBattleNPC || obj.GetBattleNPCSubKind() == BattleNpcSubKind.NpcPartyMember))
var friendlyNpcs = Svc.Objects
.Where(obj => obj != null && obj.ObjectKind == ObjectKind.BattleNpc)
.Where(obj => obj.GetNameplateKind() == NameplateKind.FriendlyBattleNPC || obj.GetBattleNPCSubKind() == BattleNpcSubKind.NpcPartyMember)
.OfType<IBattleChara>()
.ToArray();

return friendlyNpcs;
}
catch (Exception ex)
{
Expand Down
13 changes: 10 additions & 3 deletions RotationSolver.Basic/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,17 @@ internal static bool IsParty(this IGameObject gameObject)
// Add Player Chocobo Companion to Party List
unsafe
{
BattleChara* companionChocobo = DataCenter.GetCompanion();
if (companionChocobo != null)
try
{
return true;
BattleChara* companionChocobo = DataCenter.GetCompanion();
if (companionChocobo != null)
{
return true;
}
}
catch (Exception ex)
{
Svc.Log.Error(ex, "Error accessing companionChocobo");
}
}
}
Expand Down

0 comments on commit 477a8d4

Please sign in to comment.