added checks to mitigate floating point crashes

This commit is contained in:
fourtf
2020-04-19 21:05:40 +02:00
parent 6b512d1052
commit 6052846bc3
12 changed files with 74 additions and 40 deletions
+10 -9
View File
@@ -276,7 +276,8 @@ void Scrollbar::paintEvent(QPaintEvent *)
int w = this->width();
float y = 0;
float dY = float(this->height()) / float(snapshotLength);
float dY =
float(this->height()) / std::max<float>(1.0f, float(snapshotLength));
int highlightHeight =
int(std::ceil(std::max<float>(this->scale() * 2, dY)));
@@ -356,8 +357,10 @@ void Scrollbar::mouseMoveEvent(QMouseEvent *event)
{
int delta = event->pos().y() - this->lastMousePosition_.y();
setDesiredValue(this->desiredValue_ +
qreal(delta) / this->trackHeight_ * this->maximum_);
setDesiredValue(
this->desiredValue_ +
qreal(delta) /
std::max<qreal>(0.02, this->trackHeight_ * this->maximum_));
}
this->lastMousePosition_ = event->pos();
@@ -442,13 +445,11 @@ void Scrollbar::updateScroll()
this->trackHeight_ = this->height() - this->buttonHeight_ -
this->buttonHeight_ - MIN_THUMB_HEIGHT - 1;
auto div = std::max<qreal>(0.01, this->maximum_ * this->trackHeight_);
this->thumbRect_ =
QRect(0,
int(this->currentValue_ / this->maximum_ * this->trackHeight_) +
1 + this->buttonHeight_,
this->width(),
int(this->largeChange_ / this->maximum_ * this->trackHeight_) +
MIN_THUMB_HEIGHT);
QRect(0, int(this->currentValue_ / div) + 1 + this->buttonHeight_,
this->width(), int(this->largeChange_ / div) + MIN_THUMB_HEIGHT);
this->update();
}