From 8888e58dd5e1c4de634fa3a93fa7dd3b47c9b97a Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 30 Aug 2023 21:57:01 -0700 Subject: modules/swarm: handle baking errors in swarm_setup() More setup_func conversion to returning the failed setting on errors during res_setup baking. --- src/modules/swarm/swarm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/modules/swarm') diff --git a/src/modules/swarm/swarm.c b/src/modules/swarm/swarm.c index 9407168..8cf16d4 100644 --- a/src/modules/swarm/swarm.c +++ b/src/modules/swarm/swarm.c @@ -435,10 +435,10 @@ static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setti "lines", NULL, }; - const char *style; + til_setting_t *style; int r; - r = til_settings_get_and_describe_value(settings, + r = til_settings_get_and_describe_setting(settings, &(til_setting_spec_t){ .name = "Particle drawing style", .key = "style", @@ -454,16 +454,22 @@ static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setti if (res_setup) { swarm_setup_t *setup; + unsigned i; setup = til_setup_new(settings, sizeof(*setup), NULL, &swarm_module); if (!setup) return -ENOMEM; - for (int i = 0; styles[i]; i++) { - if (!strcasecmp(styles[i], style)) + for (i = 0; styles[i]; i++) { + if (!strcasecmp(styles[i], style->value)) { setup->draw_style = i; + break; + } } + if (!styles[i]) + return til_setup_free_with_failed_setting_ret_err(&setup->til_setup, style, res_setting, -EINVAL); + *res_setup = &setup->til_setup; } -- cgit v1.2.3