macOS: Fix exception when drawing scrollbars with zero-range

Terminating app due to uncaught exception 'CALayerInvalidGeometry',
  reason: 'CALayer position contains NaN: [nan nan]'

 0 CoreFoundation   __exceptionPreprocess
 1 libobjc.A.dylib  objc_exception_throw
 2 CoreFoundation   +[NSException raise:format:]
 3 QuartzCore       _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb
 4 QuartzCore       -[CALayer setPosition:]
 5 QuartzCore       -[CALayer setFrame:]
 6 AppKit           -[NSScrollerImp _updateLayerGeometry]
 7 AppKit           -[NSScroller setFloatValue:knobProportion:]
 8 libqmacstyle     setupScroller(NSScroller*, QStyleOptionSlider const*)
 9 libqmacstyle     QMacStyle::drawComplexControl(...)

Change-Id: I5afe7e7d3e94ff1d9ee34f5a9bc0d229d4f7c4c6
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2017-07-14 17:22:23 +02:00
parent 97d471c99f
commit 8fad51b7bc

View File

@ -300,7 +300,8 @@ static bool setupScroller(NSScroller *scroller, const QStyleOptionSlider *sb)
if (qFuzzyIsNull(length)) if (qFuzzyIsNull(length))
return false; return false;
const qreal proportion = sb->pageStep / length; const qreal proportion = sb->pageStep / length;
qreal value = qreal(sb->sliderValue - sb->minimum) / qreal(sb->maximum - sb->minimum); const qreal range = qreal(sb->maximum - sb->minimum);
qreal value = range ? qreal(sb->sliderValue - sb->minimum) / range : 0;
if (sb->orientation == Qt::Horizontal && sb->direction == Qt::RightToLeft) if (sb->orientation == Qt::Horizontal && sb->direction == Qt::RightToLeft)
value = 1.0 - value; value = 1.0 - value;