Skip to content

Fix infinite loop crash when Levels Gamma is set to 0#2041

Merged
cameronwhite merged 2 commits into
PintaProject:masterfrom
levanel:fix-levels-crash
Mar 18, 2026
Merged

Fix infinite loop crash when Levels Gamma is set to 0#2041
cameronwhite merged 2 commits into
PintaProject:masterfrom
levanel:fix-levels-crash

Conversation

@levanel

@levanel levanel commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #2035

Description
This PR fixes a bug where the application permanently freezes if the user drags the gamma (midtones) slider down to 0.

The freeze was caused by an infinite do-while loop in {UpdateGammaByMask(float val)}. The UI allows the user to request a value of 0 , but the underlying engine strictly clamps Gamma to a minimum of 0.1 . Because the target value could never be reached, the loop never exited locking up the main thread.

Changes
Added 'val = Math.Clamp(val, 0.1f, 10.0f);' at the start of {UpdateGammaByMask} in Effects.LevelsDialog.cs to ensure the requested value matches the physical limits before the loop begins.


private void UpdateGammaByMask (float val)
{
val = Math.Clamp(val, 0.1f, 10.0f);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there was an error from the code formatting check in the CI build. In general you can run dotnet format, but the specific fix here is adding a space before the bracket Clamp (val

private void UpdateGammaByMask (float val)
{
val = Math.Clamp(val, 0.1f, 10.0f);
if (!(mask.R || mask.G || mask.B))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! The logic seems good to me with this fix.

Since these 0.1f and 10.0f values also occur a couple times in UnaryPixelOps.cs, could you extract them into public constants on the Level adjustment's class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey! Ive moved the gamma bounds to MinGamma and MaxGamma constants in UnaryPixelOps.Level and updated all references in UnaryPixelOps.cs and LevelsDialog.cs. I also fixed the formatting in LevelsDialog.cs to resolve the CI failure. Verified the fix locally via Flatpak; let me know if you need anything else!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the contribution! 🎉

@cameronwhite cameronwhite merged commit b97cc91 into PintaProject:master Mar 18, 2026
7 checks passed
@pedropaulosuzuki pedropaulosuzuki mentioned this pull request Mar 30, 2026
6 tasks
cameronwhite pushed a commit that referenced this pull request Mar 31, 2026
cameronwhite pushed a commit that referenced this pull request Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Pinta freezes completely when holding the '-' button to bring Levels Gamma down to 0

2 participants