Skip to content

Commit

Permalink
Added safety check
Browse files Browse the repository at this point in the history
  • Loading branch information
d87 committed Sep 29, 2024
1 parent faa8c25 commit 847585b
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions CustomizePlus/Armatures/Data/ModelBone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ public hkQsTransformf GetGameTransform(CharacterBase* cBase, PoseType refFrame)
if (targetPose == null) return null;
const PropagateOrNot DO_NOT_PROPAGATE = 0;

if (BoneIndex >= targetPose->Skeleton->Bones.Length) return null;

return refFrame switch
{
PoseType.Local => targetPose->AccessBoneLocalSpace(BoneIndex),
Expand Down Expand Up @@ -335,23 +337,26 @@ public unsafe void PropagateChildren(CharacterBase* cBase, hkQsTransformf* trans
{
// Plugin.Logger.Debug($"Propagating to {child.BoneName}...");
var access = child.GetGameTransformAccess(cBase, PoseType.Model);
if (access != null)
{

var offset = access->Translation.ToVector3() - sourcePos;
var offset = access->Translation.ToVector3() - sourcePos;

var matrix = InteropAlloc.GetMatrix(access);
if (propagateScale)
{
var scaleMatrix = Matrix4x4.CreateScale(deltaScale, Vector3.Zero);
matrix *= scaleMatrix;
offset = Vector3.Transform(offset, scaleMatrix);
}
if (propagateRotation)
{
matrix *= Matrix4x4.CreateFromQuaternion(deltaRot);
offset = Vector3.Transform(offset, deltaRot);
var matrix = InteropAlloc.GetMatrix(access);
if (propagateScale)
{
var scaleMatrix = Matrix4x4.CreateScale(deltaScale, Vector3.Zero);
matrix *= scaleMatrix;
offset = Vector3.Transform(offset, scaleMatrix);
}
if (propagateRotation)
{
matrix *= Matrix4x4.CreateFromQuaternion(deltaRot);
offset = Vector3.Transform(offset, deltaRot);
}
matrix.Translation = deltaPos + sourcePos + offset;
InteropAlloc.SetMatrix(access, matrix);
}
matrix.Translation = deltaPos + sourcePos + offset;
InteropAlloc.SetMatrix(access, matrix);
}
}

Expand Down

0 comments on commit 847585b

Please sign in to comment.