Description
When using the Levels adjustment, dragging the Gamma (midtones) slider down to 0 causes the entire application (at 0.1) to lock up and freeze completely.
To Reproduce
1)Open any image.
2)Go to Adjustments ->Levels.
3)Try dragging the middle Gamma slider all the way to 0 by using the '-' minus sign
4)The application immediately freezes and has to be force killed.
Additional Info

(as it reaches 0.1, it crashes)

(user is forced to terminate the session)
Cause
The freeze is caused by an infinite do-while loop inside Pinta.Effects/Dialogs/Effects.LevelsDialog.cs in the UpdateGammaByMask(float val) function.
The UI slider allows the user to slide values from 0 to 100. However, the underlying math engine (Pinta.Core/Algorithms/PixelOps/UnaryPixelOps.cs) strictly clamps Gamma between 0.1 and 10.0.
When UpdateGammaByMask is called with val =0, the do-while loop iteratively attempts to reach 0, but the math engine forces it back to 0.1 every time. Because the difference between the actual value (0.1) and the target value (0) remains larger than the 0.001 threshold, the loop never exits and locks the main thread.
Fix
Ive already tested a fix for this locally by clamping the requested value to match the mathematical engines limits right before the loop begins:
"private void UpdateGammaByMask (float val)
{
// the fix: match math engine limits to prevent infinite loop
val = Math.Clamp(val, 0.1f, 10.0f);
if (!(mask.R || mask.G || mask.B))
return;"
Id be happy to make a commit and submit a pr with the fix if the team is good with this approach!
Version
os version: Pop!_OS 22.04 LTS x86_64, Pinta version: 3.2
Description
When using the Levels adjustment, dragging the Gamma (midtones) slider down to 0 causes the entire application (at 0.1) to lock up and freeze completely.
To Reproduce
1)Open any image.
2)Go to Adjustments ->Levels.
3)Try dragging the middle Gamma slider all the way to 0 by using the '-' minus sign
4)The application immediately freezes and has to be force killed.
Additional Info
Cause
The freeze is caused by an infinite do-while loop inside Pinta.Effects/Dialogs/Effects.LevelsDialog.cs in the UpdateGammaByMask(float val) function.
The UI slider allows the user to slide values from 0 to 100. However, the underlying math engine (Pinta.Core/Algorithms/PixelOps/UnaryPixelOps.cs) strictly clamps Gamma between 0.1 and 10.0.
When UpdateGammaByMask is called with val =0, the do-while loop iteratively attempts to reach 0, but the math engine forces it back to 0.1 every time. Because the difference between the actual value (0.1) and the target value (0) remains larger than the 0.001 threshold, the loop never exits and locks the main thread.
Fix
Ive already tested a fix for this locally by clamping the requested value to match the mathematical engines limits right before the loop begins:
"private void UpdateGammaByMask (float val)
{
// the fix: match math engine limits to prevent infinite loop
val = Math.Clamp(val, 0.1f, 10.0f);
if (!(mask.R || mask.G || mask.B))
return;"
Id be happy to make a commit and submit a pr with the fix if the team is good with this approach!
Version
os version: Pop!_OS 22.04 LTS x86_64, Pinta version: 3.2