Skip to content

Commit 8b5e22c

Browse files
author
Mark Stalzer
committed
poser_mpfit: skip non-finite optical angles instead of passing to solver
Corrupt optical angles (bad FPGA timestamps during USB disturbances) can reach construct_input_from_scene() as NaN or Inf. Passing a non-finite value into the MPFIT solver causes it to produce a garbage pose which then assert-crashes downstream (observed as assert(!isnan(lhs[lh].Rot[0]))). Add an isfinite() check before emplacing each measurement. Non-finite angles are skipped with a one-time stderr warning. One dropped measurement has negligible effect on the pose solve; crashing does not.
1 parent eb409fc commit 8b5e22c

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/poser_mpfit.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,21 @@ static size_t construct_input_from_scene(const MPFITData *d, survive_long_timeco
187187
if (isReadingValue) {
188188
const FLT *a = scene->angles[sensor][lh];
189189

190+
/* Guard against non-finite angles from corrupted optical data
191+
* (bad FPGA timestamps during USB disturbances). Passing NaN
192+
* into the MPFIT solver causes it to produce a garbage pose
193+
* that can then assert-crash downstream. One dropped measurement
194+
* has negligible effect on the pose solve. */
195+
if (!isfinite(a[axis])) {
196+
static int warned = 0;
197+
if (!warned) {
198+
fprintf(stderr, "[libsurvive WARN] poser_mpfit: NaN optical angle sensor %d lh %d axis %d; suppressing further\n",
199+
(int)sensor, (int)lh, (int)axis);
200+
warned = 1;
201+
}
202+
continue;
203+
}
204+
190205
survive_optimizer_measurement *meas =
191206
survive_optimizer_emplace_meas(mpfitctx, survive_optimizer_measurement_type_light);
192207

0 commit comments

Comments
 (0)