diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 3ed60eaa6e6..d0ce06cbf03 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -21,6 +21,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released ### Fixed - Speed up NML import in existing tracings for NMLs with many trees (20,000+). [#4742](https://github.com/scalableminds/webknossos/pull/4742) - Fixed tree groups when uploading NMLs with multi-component trees. [#4735](https://github.com/scalableminds/webknossos/pull/4735) +- Fixed that invalid number values in slider settings could crash webKnossos. [#4758](https://github.com/scalableminds/webknossos/pull/4758) ### Removed - diff --git a/frontend/javascripts/oxalis/view/settings/setting_input_views.js b/frontend/javascripts/oxalis/view/settings/setting_input_views.js index d9c5291ce26..7bd60568127 100644 --- a/frontend/javascripts/oxalis/view/settings/setting_input_views.js +++ b/frontend/javascripts/oxalis/view/settings/setting_input_views.js @@ -1,6 +1,7 @@ // @flow import { Row, Col, Slider, InputNumber, Switch, Tooltip, Input, Icon, Select } from "antd"; import * as React from "react"; +import _ from "lodash"; import type { Vector3, Vector6 } from "oxalis/constants"; import * as Utils from "libs/utils"; @@ -23,13 +24,21 @@ export class NumberSliderSetting extends React.PureComponent { - if (this.props.min <= _value && _value <= this.props.max) { + if (this.isValueValid(_value)) { this.props.onChange(_value); } }; + isValueValid = (_value: number) => + _.isNumber(_value) && _value >= this.props.min && _value <= this.props.max; + render() { - const { value, label, max, min, step, onChange, disabled } = this.props; + const { value: originalValue, label, max, min, step, onChange, disabled } = this.props; + + // Validate the provided value. If it's not valid, fallback to the midpoint between min and max. + // This check guards against broken settings which could be introduced before this component + // checked more thoroughly against invalid values. + const value = this.isValueValid(originalValue) ? originalValue : Math.floor((min + max) / 2); return (