Repository navigation
fix(scopes): 处理示波器数学计算中的 NaN 和 Inf 异常样本 (#83) - #89
Merged
Mike-Solar merged 1 commit intoNov 17, 2026
Merged
Mike-Solar merged 1 commit into
Mike-Solar merged 1 commit into
Conversation
|
Since there are forigners in this community, please speak English here. |
Mike-Solar
merged commit Nov 17, 2026
c612300
into
OakVideoEditorCommunity:main
8 of 12 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue
Fixes #83
为什么会出现这个 Bug?
原代码是用
sample.clamp(0.0, 1.0)来限制数值范围的。但浮点数有一个特性:任何数字跟
NaN比大小,结果都是false。这就导致
NaN < 0.0是假,NaN > 1.0也是假,.clamp()根本拦不住NaN,坏数据直接漏了过去:histogram_bins):NaN转成整数后变成了 0,全被当成了最暗的纯黑像素,暗部数据被污染;waveform_envelope):如果这一段数据全都是坏的,min会停在极大值、max停在极小值,导致min比max还大,绘图坐标直接倒挂;vectorscope_points):算出来的损坏坐标会直接传给界面渲染;decay_peak等):如果音量不小心算出了无穷大(+Inf),峰值线会被卡死在无穷大,之后再也掉不下来。修复方法
在 5 个计算函数里加上了
.is_finite()检查,把非正常数值(NaN和±Inf)安全拦住:histogram_bins:遇到非法数字直接continue跳过,不计入直方图;waveform_envelope:记录当前分片有没有遇到有效数字,只有正常数字才更新 min/max;如果整段全是坏数据,安全回退到默认的(0.0, 0.0);vectorscope_points:用.filter筛掉坐标损坏的点;meter_lit_segments:遇到NaN时音量表亮 0 格(静音);decay_peak:计算前把异常值做兜底清洗,防止峰值被无穷大卡死。测试验证
保留原有 6 个测试,额外补充了 4 个单元测试,专门塞入
NaN、+Inf、-Inf以及全坏数据切片进行验证:histogram_filters_nan_and_infwaveform_envelope_handles_nan_and_infvectorscope_filters_nan_and_infmeter_and_decay_nan_and_inf本地单独编译运行测试,10 个用例全部通过(0.00s):