Skip to content

Commit 8d131ba

Browse files
committed
Crashfix for SetAcqDepth rounding issue (Crashreport 21-8-2016 11:41:32)
1 parent 7aba26f commit 8d131ba

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Devices/DummyScope.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,15 @@ public uint AcquisitionDepth
492492
}
493493
else
494494
{
495-
double log2OfRatio = Math.Log((double)value / OVERVIEW_LENGTH, 2);
496-
if (log2OfRatio != (int)log2OfRatio && !isAudio)
497-
throw new ValidationException("Acquisition depth must be " + OVERVIEW_LENGTH + " * 2^N --- " + log2OfRatio.ToString() + " vs " + ((int)log2OfRatio).ToString());
495+
double log2OfRatio = Math.Log((double)value / OVERVIEW_LENGTH, 2);
496+
if (log2OfRatio != (int)log2OfRatio && !isAudio)
497+
{
498+
//this only happens on some platforms. If it happens, the difference is like 20,9999999996641 vs 20
499+
//probably rounding issue -> round and correct instead of crash
500+
Logger.Error("Acquisition depth must be " + OVERVIEW_LENGTH + " * 2^N --- " + log2OfRatio.ToString() + " vs " + ((int)log2OfRatio).ToString());
501+
log2OfRatio = (int)Math.Round(log2OfRatio);
502+
value = (uint)Math.Pow(2, log2OfRatio);
503+
}
498504
if (value > ACQUISITION_DEPTH_MAX)
499505
acquisitionDepth = ACQUISITION_DEPTH_MAX;
500506
else

0 commit comments

Comments
 (0)