From 69c525602992a607df444d897397893ce798c492 Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 10:25:12 +0200 Subject: [PATCH 1/5] agg: fix -Wmaybe-uninitialized error in gradient with GCC 16 The gradient wrapper members are constructed after the base class, so the base class cannot initialize them in its constructor. GCC 16 rejects the previous layout with -Wmaybe-uninitialized under -Werror. Store pointers initialized in the derived class constructor bodies via init_gradients() instead. --- src/veg/gradient.cpp | 16 +++++++--------- src/veg/gradient.hpp | 34 ++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/veg/gradient.cpp b/src/veg/gradient.cpp index 99226b1..c535ae3 100644 --- a/src/veg/gradient.cpp +++ b/src/veg/gradient.cpp @@ -56,11 +56,10 @@ gradient::~gradient() } linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2& p1) +{ #if VEG_BACKEND == VEG_BACKEND_AGG - : - gradient(this->linear_pad, this->linear_reflect, this->linear_repeat) + this->init_gradients(&this->linear_pad, &this->linear_reflect, &this->linear_repeat); #endif -{ #if VEG_BACKEND == VEG_BACKEND_CAIRO this->pattern = cairo_pattern_create_linear( backend_real(p0.x()), @@ -91,11 +90,10 @@ linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2< } radial_gradient::radial_gradient(const r4::vector2& f, const r4::vector2& c, real r) +{ #if VEG_BACKEND == VEG_BACKEND_AGG - : - gradient(this->radial_pad, this->radial_reflect, this->radial_repeat) + this->init_gradients(&this->radial_pad, &this->radial_reflect, &this->radial_repeat); #endif -{ #if VEG_BACKEND == VEG_BACKEND_CAIRO this->pattern = cairo_pattern_create_radial( backend_real(f.x()), @@ -160,13 +158,13 @@ void gradient::set_spread_method(gradient_spread_method spread_method) default: utki::assert(false, SL); case gradient_spread_method::pad: - this->cur_grad = &this->pad; + this->cur_grad = this->pad; break; case gradient_spread_method::reflect: - this->cur_grad = &this->reflect; + this->cur_grad = this->reflect; break; case gradient_spread_method::repeat: - this->cur_grad = &this->repeat; + this->cur_grad = this->repeat; break; } #endif diff --git a/src/veg/gradient.hpp b/src/veg/gradient.hpp index d03be8c..1a998f9 100644 --- a/src/veg/gradient.hpp +++ b/src/veg/gradient.hpp @@ -111,11 +111,27 @@ class gradient } }; - const gradient_wrapper_base& pad; - const gradient_wrapper_base& reflect; - const gradient_wrapper_base& repeat; + gradient_wrapper_base* pad = nullptr; + gradient_wrapper_base* reflect = nullptr; + gradient_wrapper_base* repeat = nullptr; + + gradient_wrapper_base* cur_grad = nullptr; + + // Derived class must call this in its constructor body, not in the + // base class constructor call, since the wrapper members are constructed + // after the base class. + void init_gradients( + gradient_wrapper_base* pad, + gradient_wrapper_base* reflect, + gradient_wrapper_base* repeat + ) { + this->pad = pad; + this->reflect = reflect; + this->repeat = repeat; + this->cur_grad = this->pad; + } - const gradient_wrapper_base* cur_grad; + gradient() = default; const gradient_wrapper_base& get_agg_gradient() const { @@ -128,16 +144,6 @@ class gradient r4::matrix2 local_matrix; - gradient( - const gradient_wrapper_base& pad, - const gradient_wrapper_base& reflect, - const gradient_wrapper_base& repeat - ) : - pad(pad), - reflect(reflect), - repeat(repeat), - cur_grad(&this->pad) - {} #endif public: From 9122e10d267b1c96db6b22ac87db22f0c538e988 Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 10:53:30 +0200 Subject: [PATCH 2/5] agg: remove unused gradient wrapper pointers from the base gradient class Address review: the base class only needs cur_grad. Derived classes set it in their constructor bodies and override the now-virtual set_spread_method() with their own wrappers. --- src/veg/gradient.cpp | 46 ++++++++++++++++++++++++++++++++++---------- src/veg/gradient.hpp | 27 ++++++++------------------ 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/veg/gradient.cpp b/src/veg/gradient.cpp index c535ae3..c1e996b 100644 --- a/src/veg/gradient.cpp +++ b/src/veg/gradient.cpp @@ -57,9 +57,6 @@ gradient::~gradient() linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2& p1) { -#if VEG_BACKEND == VEG_BACKEND_AGG - this->init_gradients(&this->linear_pad, &this->linear_reflect, &this->linear_repeat); -#endif #if VEG_BACKEND == VEG_BACKEND_CAIRO this->pattern = cairo_pattern_create_linear( backend_real(p0.x()), @@ -71,6 +68,9 @@ linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2< throw std::runtime_error("cairo_pattern_create_linear() failed"); } #elif VEG_BACKEND == VEG_BACKEND_AGG + // default spread method + this->cur_grad = &this->linear_pad; + auto v = p1 - p0; auto len = v.norm(); @@ -91,9 +91,6 @@ linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2< radial_gradient::radial_gradient(const r4::vector2& f, const r4::vector2& c, real r) { -#if VEG_BACKEND == VEG_BACKEND_AGG - this->init_gradients(&this->radial_pad, &this->radial_reflect, &this->radial_repeat); -#endif #if VEG_BACKEND == VEG_BACKEND_CAIRO this->pattern = cairo_pattern_create_radial( backend_real(f.x()), @@ -107,6 +104,9 @@ radial_gradient::radial_gradient(const r4::vector2& f, const r4::vector2cur_grad = &this->radial_pad; + // gradient parameters are stretched so that the gradient radius becomes // color_lut_size, this is for optimal color picking from the color_lut real lut_r = decltype(gradient::lut)::color_lut_size; @@ -154,21 +154,47 @@ void gradient::set_spread_method(gradient_spread_method spread_method) SL ); #elif VEG_BACKEND == VEG_BACKEND_AGG + // this method is overridden by the derived classes, since the concrete + // gradient wrappers are members of the derived classes + utki::assert(false, SL); +#endif +} + +#if VEG_BACKEND == VEG_BACKEND_AGG +void linear_gradient::set_spread_method(gradient_spread_method spread_method) +{ switch (spread_method) { default: utki::assert(false, SL); case gradient_spread_method::pad: - this->cur_grad = this->pad; + this->cur_grad = &this->linear_pad; break; case gradient_spread_method::reflect: - this->cur_grad = this->reflect; + this->cur_grad = &this->linear_reflect; break; case gradient_spread_method::repeat: - this->cur_grad = this->repeat; + this->cur_grad = &this->linear_repeat; + break; + } +} + +void radial_gradient::set_spread_method(gradient_spread_method spread_method) +{ + switch (spread_method) { + default: + utki::assert(false, SL); + case gradient_spread_method::pad: + this->cur_grad = &this->radial_pad; + break; + case gradient_spread_method::reflect: + this->cur_grad = &this->radial_reflect; + break; + case gradient_spread_method::repeat: + this->cur_grad = &this->radial_repeat; break; } -#endif } +#endif void gradient::set_stops(utki::span stops) { diff --git a/src/veg/gradient.hpp b/src/veg/gradient.hpp index 1a998f9..15f0473 100644 --- a/src/veg/gradient.hpp +++ b/src/veg/gradient.hpp @@ -111,26 +111,11 @@ class gradient } }; - gradient_wrapper_base* pad = nullptr; - gradient_wrapper_base* reflect = nullptr; - gradient_wrapper_base* repeat = nullptr; - + // The concrete gradient wrappers are members of the derived classes, so + // derived classes must set this in their constructor bodies and override + // set_spread_method(). gradient_wrapper_base* cur_grad = nullptr; - // Derived class must call this in its constructor body, not in the - // base class constructor call, since the wrapper members are constructed - // after the base class. - void init_gradients( - gradient_wrapper_base* pad, - gradient_wrapper_base* reflect, - gradient_wrapper_base* repeat - ) { - this->pad = pad; - this->reflect = reflect; - this->repeat = repeat; - this->cur_grad = this->pad; - } - gradient() = default; const gradient_wrapper_base& get_agg_gradient() const @@ -161,7 +146,7 @@ class gradient * Spread method is a behavior of the gradient when it reaches its final * gradient stop. */ - void set_spread_method(gradient_spread_method spread_method); + virtual void set_spread_method(gradient_spread_method spread_method); /** * @brief Set gradient stops. @@ -186,6 +171,8 @@ class linear_gradient : public gradient gradient_wrapper linear_pad; spread_gradient_wrapper linear_reflect; spread_gradient_wrapper linear_repeat; + + void set_spread_method(gradient_spread_method spread_method) override; #endif public: @@ -209,6 +196,8 @@ class radial_gradient : public gradient gradient_wrapper radial_pad; spread_gradient_wrapper radial_reflect; spread_gradient_wrapper radial_repeat; + + void set_spread_method(gradient_spread_method spread_method) override; #endif public: From 3a58757db38564b7ef44ddac0f6f97145a9993bb Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 11:39:30 +0200 Subject: [PATCH 3/5] agg: provide spread method wrappers via get_spread_method_wrapper() Address review: instead of overriding set_spread_method() in the derived classes, introduce the pure virtual protected gradient::get_spread_method_wrapper() and override it in linear_gradient and radial_gradient. The gradient wrappers are kept in a utki::enum_array indexed by gradient_spread_method (added the enum_size item to the enum). The base set_spread_method() implementation uses the new accessor. --- src/veg/gradient.cpp | 52 ++++++++++---------------------------------- src/veg/gradient.hpp | 28 +++++++++++++++++++----- 2 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/veg/gradient.cpp b/src/veg/gradient.cpp index c1e996b..46c0990 100644 --- a/src/veg/gradient.cpp +++ b/src/veg/gradient.cpp @@ -68,8 +68,12 @@ linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2< throw std::runtime_error("cairo_pattern_create_linear() failed"); } #elif VEG_BACKEND == VEG_BACKEND_AGG + // register the gradient wrappers for the spread methods + this->spread_wrappers[gradient_spread_method::pad] = &this->linear_pad; + this->spread_wrappers[gradient_spread_method::reflect] = &this->linear_reflect; + this->spread_wrappers[gradient_spread_method::repeat] = &this->linear_repeat; // default spread method - this->cur_grad = &this->linear_pad; + this->cur_grad = this->spread_wrappers[gradient_spread_method::pad]; auto v = p1 - p0; auto len = v.norm(); @@ -104,8 +108,12 @@ radial_gradient::radial_gradient(const r4::vector2& f, const r4::vector2spread_wrappers[gradient_spread_method::pad] = &this->radial_pad; + this->spread_wrappers[gradient_spread_method::reflect] = &this->radial_reflect; + this->spread_wrappers[gradient_spread_method::repeat] = &this->radial_repeat; // default spread method - this->cur_grad = &this->radial_pad; + this->cur_grad = this->spread_wrappers[gradient_spread_method::pad]; // gradient parameters are stretched so that the gradient radius becomes // color_lut_size, this is for optimal color picking from the color_lut @@ -154,48 +162,10 @@ void gradient::set_spread_method(gradient_spread_method spread_method) SL ); #elif VEG_BACKEND == VEG_BACKEND_AGG - // this method is overridden by the derived classes, since the concrete - // gradient wrappers are members of the derived classes - utki::assert(false, SL); + this->cur_grad = &this->get_spread_method_wrapper(spread_method); #endif } -#if VEG_BACKEND == VEG_BACKEND_AGG -void linear_gradient::set_spread_method(gradient_spread_method spread_method) -{ - switch (spread_method) { - default: - utki::assert(false, SL); - case gradient_spread_method::pad: - this->cur_grad = &this->linear_pad; - break; - case gradient_spread_method::reflect: - this->cur_grad = &this->linear_reflect; - break; - case gradient_spread_method::repeat: - this->cur_grad = &this->linear_repeat; - break; - } -} - -void radial_gradient::set_spread_method(gradient_spread_method spread_method) -{ - switch (spread_method) { - default: - utki::assert(false, SL); - case gradient_spread_method::pad: - this->cur_grad = &this->radial_pad; - break; - case gradient_spread_method::reflect: - this->cur_grad = &this->radial_reflect; - break; - case gradient_spread_method::repeat: - this->cur_grad = &this->radial_repeat; - break; - } -} -#endif - void gradient::set_stops(utki::span stops) { #if VEG_BACKEND == VEG_BACKEND_CAIRO diff --git a/src/veg/gradient.hpp b/src/veg/gradient.hpp index 15f0473..6b43513 100644 --- a/src/veg/gradient.hpp +++ b/src/veg/gradient.hpp @@ -37,6 +37,8 @@ SOFTWARE. #elif VEG_BACKEND == VEG_BACKEND_AGG # include # include + +# include #endif namespace veg { @@ -59,7 +61,9 @@ enum class gradient_spread_method { /** * @brief Repeat gradients stops in direct order. */ - repeat + repeat, + + enum_size }; /** @@ -112,10 +116,12 @@ class gradient }; // The concrete gradient wrappers are members of the derived classes, so - // derived classes must set this in their constructor bodies and override - // set_spread_method(). + // derived classes must set this in their constructor bodies and provide + // the wrappers via get_spread_method_wrapper(). gradient_wrapper_base* cur_grad = nullptr; + virtual gradient_wrapper_base& get_spread_method_wrapper(gradient_spread_method spread_method) = 0; + gradient() = default; const gradient_wrapper_base& get_agg_gradient() const @@ -146,7 +152,7 @@ class gradient * Spread method is a behavior of the gradient when it reaches its final * gradient stop. */ - virtual void set_spread_method(gradient_spread_method spread_method); + void set_spread_method(gradient_spread_method spread_method); /** * @brief Set gradient stops. @@ -172,7 +178,12 @@ class linear_gradient : public gradient spread_gradient_wrapper linear_reflect; spread_gradient_wrapper linear_repeat; - void set_spread_method(gradient_spread_method spread_method) override; + utki::enum_array spread_wrappers; + + gradient_wrapper_base& get_spread_method_wrapper(gradient_spread_method spread_method) override + { + return *this->spread_wrappers[spread_method]; + } #endif public: @@ -197,7 +208,12 @@ class radial_gradient : public gradient spread_gradient_wrapper radial_reflect; spread_gradient_wrapper radial_repeat; - void set_spread_method(gradient_spread_method spread_method) override; + utki::enum_array spread_wrappers; + + gradient_wrapper_base& get_spread_method_wrapper(gradient_spread_method spread_method) override + { + return *this->spread_wrappers[spread_method]; + } #endif public: From 5c81f6b45b19adf114e717283b6da42af76a327e Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 11:49:41 +0200 Subject: [PATCH 4/5] agg: initialize spread_wrappers in the ctor initializer list Address review: the spread wrappers array is now initialized in the constructor initializer list, and the constructors set the initial spread method via set_spread_method() instead of assigning cur_grad directly. --- src/veg/gradient.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/veg/gradient.cpp b/src/veg/gradient.cpp index 46c0990..3dacfa3 100644 --- a/src/veg/gradient.cpp +++ b/src/veg/gradient.cpp @@ -56,6 +56,14 @@ gradient::~gradient() } linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2& p1) +#if VEG_BACKEND == VEG_BACKEND_AGG +: + spread_wrappers({ + &this->linear_pad, + &this->linear_reflect, + &this->linear_repeat + }) +#endif { #if VEG_BACKEND == VEG_BACKEND_CAIRO this->pattern = cairo_pattern_create_linear( @@ -68,12 +76,8 @@ linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2< throw std::runtime_error("cairo_pattern_create_linear() failed"); } #elif VEG_BACKEND == VEG_BACKEND_AGG - // register the gradient wrappers for the spread methods - this->spread_wrappers[gradient_spread_method::pad] = &this->linear_pad; - this->spread_wrappers[gradient_spread_method::reflect] = &this->linear_reflect; - this->spread_wrappers[gradient_spread_method::repeat] = &this->linear_repeat; - // default spread method - this->cur_grad = this->spread_wrappers[gradient_spread_method::pad]; + // set the initial spread method + this->set_spread_method(gradient_spread_method::pad); auto v = p1 - p0; auto len = v.norm(); @@ -94,6 +98,14 @@ linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2< } radial_gradient::radial_gradient(const r4::vector2& f, const r4::vector2& c, real r) +#if VEG_BACKEND == VEG_BACKEND_AGG +: + spread_wrappers({ + &this->radial_pad, + &this->radial_reflect, + &this->radial_repeat + }) +#endif { #if VEG_BACKEND == VEG_BACKEND_CAIRO this->pattern = cairo_pattern_create_radial( @@ -108,12 +120,8 @@ radial_gradient::radial_gradient(const r4::vector2& f, const r4::vector2spread_wrappers[gradient_spread_method::pad] = &this->radial_pad; - this->spread_wrappers[gradient_spread_method::reflect] = &this->radial_reflect; - this->spread_wrappers[gradient_spread_method::repeat] = &this->radial_repeat; - // default spread method - this->cur_grad = this->spread_wrappers[gradient_spread_method::pad]; + // set the initial spread method + this->set_spread_method(gradient_spread_method::pad); // gradient parameters are stretched so that the gradient radius becomes // color_lut_size, this is for optimal color picking from the color_lut From b8161a194aab8f06e104b889ca7ea3cc03a644e6 Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 12:02:45 +0200 Subject: [PATCH 5/5] agg: format gradient.cpp with clang-format Address the CI lint failure: format the new constructor initializer lists per the project's clang-format configuration. --- src/veg/gradient.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/veg/gradient.cpp b/src/veg/gradient.cpp index 3dacfa3..7fb6a5d 100644 --- a/src/veg/gradient.cpp +++ b/src/veg/gradient.cpp @@ -57,12 +57,8 @@ gradient::~gradient() linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2& p1) #if VEG_BACKEND == VEG_BACKEND_AGG -: - spread_wrappers({ - &this->linear_pad, - &this->linear_reflect, - &this->linear_repeat - }) + : + spread_wrappers({&this->linear_pad, &this->linear_reflect, &this->linear_repeat}) #endif { #if VEG_BACKEND == VEG_BACKEND_CAIRO @@ -99,12 +95,8 @@ linear_gradient::linear_gradient(const r4::vector2& p0, const r4::vector2< radial_gradient::radial_gradient(const r4::vector2& f, const r4::vector2& c, real r) #if VEG_BACKEND == VEG_BACKEND_AGG -: - spread_wrappers({ - &this->radial_pad, - &this->radial_reflect, - &this->radial_repeat - }) + : + spread_wrappers({&this->radial_pad, &this->radial_reflect, &this->radial_repeat}) #endif { #if VEG_BACKEND == VEG_BACKEND_CAIRO