From b95a3e36b9a9a652b4c7540831f655b608652b24 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 24 Aug 2023 14:23:15 -0700 Subject: 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. --- src/modules/shapes/shapes.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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; } -- cgit v1.2.3