crash-proof pose fetching in animation machine
@@ -148,12 +148,15 @@ impl EvaluatePose for BlendAnimations {
}
};
- let pose_source =
- nodes[blend_pose.pose_source].eval_pose(nodes, params, animations, dt);
+ if let Some(pose_source) = nodes
+ .try_borrow(blend_pose.pose_source)
+ .map(|pose_source| pose_source.eval_pose(nodes, params, animations, dt))
+ {
self.output_pose
.borrow_mut()
.blend_with(&pose_source, weight);
}
+ }
self.output_pose.borrow()
}
@@ -255,9 +258,10 @@ impl EvaluatePose for BlendAnimationsByIndex {
if let Some(prev_index) = self.prev_index.get() {
if prev_index != current_index {
- let prev_input = &self.inputs[prev_index as usize];
- let current_input = &self.inputs[current_index as usize];
-
+ if let (Some(prev_input), Some(current_input)) = (
+ self.inputs.get(prev_index as usize),
+ self.inputs.get(current_index as usize),
+ ) {
self.blend_time
.set((self.blend_time.get() + dt).min(current_input.blend_time));
@@ -268,7 +272,8 @@ impl EvaluatePose for BlendAnimationsByIndex {
1.0 - interpolator,
);
self.output_pose.borrow_mut().blend_with(
- &nodes[current_input.pose_source].eval_pose(nodes, params, animations, dt),
+ &nodes[current_input.pose_source]
+ .eval_pose(nodes, params, animations, dt),
interpolator,
);
@@ -279,19 +284,22 @@ impl EvaluatePose for BlendAnimationsByIndex {
applied = true;
}
+ }
} else {
self.prev_index.set(Some(current_index));
}
if !applied {
- // Immediately jump to target pose.
+ // Immediately jump to target pose (if any).
self.blend_time.set(0.0);
- nodes[self.inputs[current_index as usize].pose_source]
+ if let Some(current_input) = self.inputs.get(current_index as usize) {
+ nodes[current_input.pose_source]
.eval_pose(nodes, params, animations, dt)
.clone_into(&mut *self.output_pose.borrow_mut());
}
}
+ }
self.output_pose.borrow()
}
