From 5273f26ef0b816f6f75147ef14b1fe2f20abfc32 Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Mon, 31 Mar 2025 15:54:44 -0400 Subject: [PATCH] app, pdb: fix #13480 inconsistent use of maximum radius... for generated brushes. The maximum radius we allowed for generated brushes was not used consistently everywhere. In the API call we clamped it to 0.0-32767.0, while the param_spec set min and max to 0.1 and 4000.0, and the brush editor used a maximum of 1000.0. Using a large value (probably anything larger than 4000) would sooner or later lead to a crash. Instead of manual changes everywhere, let's define a maximum and minimum in one place and use that wherever we need the min/max values. Use the values as set in the param_spec for the defines. The only place we can't easily do that is in brush.pdb, so we add a comment above our defines that the values need updating there too. Actually we should probably use more defines for other values too, that way there is less chance of min/max values getting out of synch throughout our code. --- app/actions/context-commands.c | 2 +- app/core/gimpbrushgenerated.c | 6 ++++-- app/core/gimpbrushgenerated.h | 4 ++++ app/pdb/brush-cmds.c | 2 +- app/widgets/gimpbrusheditor.c | 5 ++++- libgimp/gimpbrush_pdb.c | 4 ++-- pdb/groups/brush.pdb | 2 +- 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/actions/context-commands.c b/app/actions/context-commands.c index 1bb8d5033d..e0152676f7 100644 --- a/app/actions/context-commands.c +++ b/app/actions/context-commands.c @@ -719,7 +719,7 @@ context_brush_radius_cmd_callback (GimpAction *action, radius = action_select_value (select_type, radius, - min_radius, 4000.0, min_radius, + min_radius, GIMP_BRUSH_GENERATED_MAX_RADIUS, min_radius, 0.1, 1.0, 10.0, 0.05, FALSE); gimp_brush_generated_set_radius (generated, radius); diff --git a/app/core/gimpbrushgenerated.c b/app/core/gimpbrushgenerated.c index dacdaa8683..9ec2c048a5 100644 --- a/app/core/gimpbrushgenerated.c +++ b/app/core/gimpbrushgenerated.c @@ -141,7 +141,9 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass) g_object_class_install_property (object_class, PROP_RADIUS, g_param_spec_double ("radius", NULL, _("Brush Radius"), - 0.1, 4000.0, 5.0, + GIMP_BRUSH_GENERATED_MIN_RADIUS, + GIMP_BRUSH_GENERATED_MAX_RADIUS, + 5.0, GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); @@ -733,7 +735,7 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush, { g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0); - radius = CLAMP (radius, 0.0, 32767.0); + radius = CLAMP (radius, GIMP_BRUSH_GENERATED_MIN_RADIUS, GIMP_BRUSH_GENERATED_MAX_RADIUS); if (brush->radius != radius) { diff --git a/app/core/gimpbrushgenerated.h b/app/core/gimpbrushgenerated.h index 2df3578640..64c5a5e392 100644 --- a/app/core/gimpbrushgenerated.h +++ b/app/core/gimpbrushgenerated.h @@ -32,6 +32,10 @@ #define GIMP_BRUSH_GENERATED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGeneratedClass)) +/* When changing these values, also update it in pdb/groups/brush.pdb */ +#define GIMP_BRUSH_GENERATED_MIN_RADIUS 0.1 +#define GIMP_BRUSH_GENERATED_MAX_RADIUS 4000.0 + typedef struct _GimpBrushGeneratedClass GimpBrushGeneratedClass; struct _GimpBrushGenerated diff --git a/app/pdb/brush-cmds.c b/app/pdb/brush-cmds.c index 45b7619212..e87069b2d0 100644 --- a/app/pdb/brush-cmds.c +++ b/app/pdb/brush-cmds.c @@ -1144,7 +1144,7 @@ register_brush_procs (GimpPDB *pdb) "gimp-brush-set-radius"); gimp_procedure_set_static_help (procedure, "Sets the radius of a generated brush.", - "Sets the radius for a generated brush. Clamps radius to [0.0, 32767.0]. Returns the clamped value. Returns an error when brush is non-parametric or not editable.", + "Sets the radius for a generated brush. Clamps radius to [0.1, 4000.0]. Returns the clamped value. Returns an error when brush is non-parametric or not editable.", NULL); gimp_procedure_set_static_attribution (procedure, "Bill Skaggs ", diff --git a/app/widgets/gimpbrusheditor.c b/app/widgets/gimpbrusheditor.c index 442c1a61e8..495dde647a 100644 --- a/app/widgets/gimpbrusheditor.c +++ b/app/widgets/gimpbrusheditor.c @@ -150,7 +150,10 @@ gimp_brush_editor_init (GimpBrushEditor *editor) gtk_widget_show (box); /* brush radius scale */ - editor->radius_data = gtk_adjustment_new (0.0, 0.1, 1000.0, 1.0, 10.0, 0.0); + editor->radius_data = gtk_adjustment_new (0.0, + GIMP_BRUSH_GENERATED_MIN_RADIUS, + GIMP_BRUSH_GENERATED_MAX_RADIUS, + 1.0, 10.0, 0.0); scale = gimp_spin_scale_new (editor->radius_data, _("Radius"), 1); gtk_box_pack_start (GTK_BOX (editor->options_box), scale, FALSE, FALSE, 0); gtk_widget_show (scale); diff --git a/libgimp/gimpbrush_pdb.c b/libgimp/gimpbrush_pdb.c index 29584f44fc..de08f6ea76 100644 --- a/libgimp/gimpbrush_pdb.c +++ b/libgimp/gimpbrush_pdb.c @@ -494,8 +494,8 @@ gimp_brush_get_radius (GimpBrush *brush, * * Sets the radius of a generated brush. * - * Sets the radius for a generated brush. Clamps radius to [0.0, - * 32767.0]. Returns the clamped value. Returns an error when brush is + * Sets the radius for a generated brush. Clamps radius to [0.1, + * 4000.0]. Returns the clamped value. Returns an error when brush is * non-parametric or not editable. * * Returns: TRUE on success. diff --git a/pdb/groups/brush.pdb b/pdb/groups/brush.pdb index e6a4f3a398..22caa563e8 100644 --- a/pdb/groups/brush.pdb +++ b/pdb/groups/brush.pdb @@ -542,7 +542,7 @@ sub brush_set_radius { $help = <<'HELP'; Sets the radius for a generated brush. -Clamps radius to [0.0, 32767.0]. +Clamps radius to [0.1, 4000.0]. Returns the clamped value. Returns an error when brush is non-parametric or not editable. HELP