Skip to content

Commit

Permalink
Merge pull request #1292 from AsgardXIV/briofailfix
Browse files Browse the repository at this point in the history
Do not crash when Brio call fails
  • Loading branch information
Luminiari authored Feb 14, 2023
2 parents f110da6 + 9567e36 commit fcc5f38
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
12 changes: 10 additions & 2 deletions Anamnesis/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Anamnesis.GUI;
using XivToolsWpf;
using XivToolsWpf.Windows;
using XivToolsWpf.Extensions;
using Serilog;

/// <summary>
/// Interaction logic for MainWindow.xaml.
Expand Down Expand Up @@ -326,9 +327,16 @@ private async void OnDespawnActorClicked(object sender, RoutedEventArgs e)
if (!actor.IsValid || actor.Memory == null)
return;

if(await Brio.Brio.Despawn(actor.Memory.ObjectIndex))
try
{
TargetService.UnpinActor(actor);
if (await Brio.Brio.Despawn(actor.Memory.ObjectIndex))
{
TargetService.UnpinActor(actor);
}
}
catch(Exception ex)
{
Log.Error("Failed to despawn actor", ex);
}
}
}
Expand Down
62 changes: 37 additions & 25 deletions Anamnesis/Views/TargetSelectorView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Anamnesis.Views;
using Anamnesis.Memory;
using Anamnesis.Services;
using Anamnesis.Styles.Drawers;
using Serilog;
using XivToolsWpf;

public abstract class TargetSelectorDrawer : SelectorDrawer<ActorBasicMemory>
Expand Down Expand Up @@ -186,37 +187,48 @@ private async void OnCreateActorClicked(object sender, RoutedEventArgs e)
if (PoseService.Instance.IsEnabled || PoseService.Instance.FreezeWorldPosition)
options |= SpawnOptions.ApplyModelPosition;

var nextActorId = await Brio.Spawn(options);
if(nextActorId != -1)
try
{
var actors = ActorService.Instance.GetAllActors(true);
var newActor = actors.SingleOrDefault(i => i.ObjectIndex == nextActorId);
if(newActor != null)
var nextActorId = await Brio.Spawn(options);
if (nextActorId != -1)
{
if (PoseService.Instance.IsEnabled)
var actors = ActorService.Instance.GetAllActors(true);
var newActor = actors.SingleOrDefault(i => i.ObjectIndex == nextActorId);
if (newActor != null)
{
// We try and load the A-Pose if it's available
var path = FileService.ParseToFilePath(FileService.StandardPoseDirectory.Path);
path = path + Path.Combine("Unisex", "A-Pose.pose");

if (File.Exists(path))
if (PoseService.Instance.IsEnabled)
{
PoseFile? poseFile = new PoseFile().Deserialize(File.OpenRead(path)) as PoseFile;
if (poseFile == null)
return;

SkeletonVisual3d skeletonVisual3D = new();
ActorMemory fullActor = new ActorMemory();
fullActor.SetAddress(newActor.Address);
fullActor.Tick();
await skeletonVisual3D.SetActor(fullActor);
await poseFile.Apply(fullActor, skeletonVisual3D, null, PoseFile.Mode.Rotation);
}
// We try and load the A-Pose if it's available
var path = FileService.ParseToFilePath(FileService.StandardPoseDirectory.Path);
path = path + Path.Combine("Unisex", "A-Pose.pose");

if (File.Exists(path))
{
PoseFile? poseFile = new PoseFile().Deserialize(File.OpenRead(path)) as PoseFile;
if (poseFile == null)
return;

SkeletonVisual3d skeletonVisual3D = new();
ActorMemory fullActor = new ActorMemory();
fullActor.SetAddress(newActor.Address);
fullActor.Tick();
await skeletonVisual3D.SetActor(fullActor);
await poseFile.Apply(fullActor, skeletonVisual3D, null, PoseFile.Mode.Rotation);
}
}

this.Value = newActor;
this.OnSelectionChanged(true);
}

this.Value = newActor;
this.OnSelectionChanged(true);
}
else
{
throw new Exception("Brio could not spawn actor");
}
}
catch(Exception ex)
{
Log.Error("Failed to spawn actor", ex);
}
}
}

0 comments on commit fcc5f38

Please sign in to comment.