From 6ad35f2c1a2faac42c80b2c8dcdce2887c670bda Mon Sep 17 00:00:00 2001 From: Rakosn1cek Date: Fri, 4 Sep 2026 15:46:34 +0100 Subject: [PATCH] Fix recursive input event loop causing stack overflow on colour picker --- .../Widgets/ColorPickerSlider.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Pinta.Gui.Widgets/Widgets/ColorPickerSlider.cs b/Pinta.Gui.Widgets/Widgets/ColorPickerSlider.cs index 49937928ac..890e4ad725 100644 --- a/Pinta.Gui.Widgets/Widgets/ColorPickerSlider.cs +++ b/Pinta.Gui.Widgets/Widgets/ColorPickerSlider.cs @@ -24,6 +24,8 @@ public enum Component private const int PADDING_WIDTH = 14; private const int PADDING_HEIGHT = 10; + private bool suppress_input_events; + private Component component; private Color color; @@ -114,7 +116,13 @@ private void UpdateColorFromDrag (double x) private void UpdateColorValue (double value) { double clampedValue = Math.Clamp (Math.Round (value), 0, GetMaxValue (component)); - input_field.SetText (clampedValue.ToString (CultureInfo.InvariantCulture)); + + suppress_input_events = true; + try { + input_field.SetText (clampedValue.ToString (CultureInfo.InvariantCulture)); + } finally { + suppress_input_events = false; + } color = UpdateValue (color, component, clampedValue); gradient_slider.QueueDraw (); @@ -160,6 +168,9 @@ private void DrawCursor (Context context, int width, int height) private void OnInputFieldChanged (Gtk.Editable inputField, EventArgs e) { + if (suppress_input_events) + return; + string text = inputField.GetText (); bool success = double.TryParse ( @@ -192,10 +203,15 @@ public Color Color { double componentValue = ExtractValue (value, component); if (!input_field.IsEditingText ()) { - // Ensure we don't get an infinite loop of "value changed" events string newText = Convert.ToInt32 (componentValue).ToString (); - if (newText != input_field.GetText ()) - input_field.SetText (newText); + if (newText != input_field.GetText ()) { + suppress_input_events = true; + try { + input_field.SetText (newText); + } finally { + suppress_input_events = false; + } + } } gradient_slider.QueueDraw ();