Skip to content

Commit b606f2a

Browse files
authored
Fix divide by zero in ui::Slider (#19957) (#20019)
* Added RenderTexture::saveToFileAsNonPMA() to save images without PMA. Set the PMA parameter to true when calling initWithRawData() inside RenderTexture::newImage(), since textures are PMA. Renamed Image::premultipliedAlpha() to Image::premultiplyAlpha() to better reflect it's action, and made it public. Added Image::reversePremultipliedAlpha() to allow the reversing of the PMA. Updated CCImage-ios.mm to set the correct bitmapInfo for PMA and non-PMA images before saving a file. Updated RenderTextureTest::RenderTextureSave() to cater for non-PMA file saving. * [CCImage-ios.mm] Fixed indentation. * [UISlider.cpp] Divide by 0 error if _maxPercent is equal to 0, which is an allowed value.
1 parent ba2f9ac commit b606f2a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cocos/ui/UISlider.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,15 @@ void Slider::setPercent(int percent)
465465

466466
void Slider::updateVisualSlider()
467467
{
468-
float res = 1.0 * _percent / _maxPercent;
468+
float res;
469+
if (_maxPercent > 0)
470+
{
471+
res = 1.0f * _percent / _maxPercent;
472+
}
473+
else
474+
{
475+
res = 0.f;
476+
}
469477
float dis = _barLength * res;
470478
_slidBallRenderer->setPosition(dis, _contentSize.height / 2.0f);
471479
if (_scale9Enabled)

0 commit comments

Comments
 (0)