summaryrefslogtreecommitdiff
path: root/src/modules/shapes
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-24 14:23:15 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-24 14:23:15 -0700
commitb95a3e36b9a9a652b4c7540831f655b608652b24 (patch)
tree1a611ac1a04cda56bffa112ffeef83c8c9ea0106 /src/modules/shapes
parentffc5dddedf9edf7ccb9ca13fe9b29f322811fd52 (diff)
modules/shapes: clamp {scale,pinch_factor} to 0-1
It might be worthwhile to support >1 for these, but as-is it crashes due to assumptions WRT shape size not exceeding frame dimensions. This just prevents crashes if someone tries putting a >1 value in something like a rkt track for scale/pinch_factor.
Diffstat (limited to 'src/modules/shapes')
-rw-r--r--src/modules/shapes/shapes.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/modules/shapes/shapes.c b/src/modules/shapes/shapes.c
index 7dd590a..63395d8 100644
--- a/src/modules/shapes/shapes.c
+++ b/src/modules/shapes/shapes.c
@@ -203,7 +203,6 @@ static shapes_radcache_t * shapes_radcache_new(unsigned width, unsigned height)
static void shapes_update_taps(shapes_context_t *ctxt, til_stream_t *stream, float dt)
{
- /* FIXME: these vars probably need to be clamped within safe bounds to prevent crashing */
if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.scale))
*ctxt->scale = ctxt->setup->scale;
else
@@ -238,6 +237,16 @@ static void shapes_update_taps(shapes_context_t *ctxt, til_stream_t *stream, flo
ctxt->vars.n_points = *ctxt->n_points;
}
+ if (ctxt->vars.scale > 1.f)
+ ctxt->vars.scale = 1.f;
+ else if (ctxt->vars.scale < 0.f)
+ ctxt->vars.scale = 0.f;
+
+ if (ctxt->vars.pinch_factor > 1.f)
+ ctxt->vars.pinch_factor = 1.f;
+ else if (ctxt->vars.pinch_factor < 0.f)
+ ctxt->vars.pinch_factor = 0.f;
+
ctxt->spin += dt * ctxt->vars.spin_rate * SHAPES_SPIN_BASE;
ctxt->pinch_spin += dt * ctxt->vars.pinch_spin_rate * SHAPES_SPIN_BASE;
}
© All Rights Reserved