Skip to content

Commit 69e7825

Browse files
rh101minggo
authored andcommitted
Fix divide by zero in ui::Slider (#19957)
* 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 eb466a3 commit 69e7825

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cocos/ui/UISlider.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,15 @@ void Slider::setPercent(int percent)
467467

468468
void Slider::updateVisualSlider()
469469
{
470-
float res = 1.0 * _percent / _maxPercent;
470+
float res;
471+
if (_maxPercent > 0)
472+
{
473+
res = 1.0f * _percent / _maxPercent;
474+
}
475+
else
476+
{
477+
res = 0.f;
478+
}
471479
float dis = _barLength * res;
472480
_slidBallRenderer->setPosition(dis, _contentSize.height / 2.0f);
473481
if (_scale9Enabled)

0 commit comments

Comments
 (0)