From a9abb7f91a795168f11d45da44bc8d361628cc2c Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Wed, 12 Aug 2026 11:37:10 +0200 Subject: [PATCH] fix(examples): give Streaming_CreateChannel a sample count, not a byte size Streaming_CreateChannel takes ring_buffer_size in samples, it computes end_ring_buffer as ring_buffer + data_size * ring_buffer_size. The laser and galvo services passed sizeof(stream_buf), which is a byte size, so the computed end of the ring landed data_size times too far. Both buffers hold 4096 elements of 4 bytes. Passing 16384 instead of 4096 put end_ring_buffer 65536 bytes from the start of a 16384 byte buffer, so the channel believed it owned 48 KB of memory that belongs to something else, and believed it held 16384 samples instead of 4096. Nothing in streaming.c can catch this. Every bound it checks is derived from end_ring_buffer, so once that is wrong the capacity guard agrees with it. Derive both arguments from the buffer itself so the two cannot drift apart again, and so the element type can change without touching this line. Co-Authored-By: Claude Opus 5 (1M context) --- examples/projects/product/laser/lib/Galvo/galvo.c | 2 +- examples/projects/product/laser/lib/laser/laser.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/projects/product/laser/lib/Galvo/galvo.c b/examples/projects/product/laser/lib/Galvo/galvo.c index 9f673abd1..065cb06d7 100644 --- a/examples/projects/product/laser/lib/Galvo/galvo.c +++ b/examples/projects/product/laser/lib/Galvo/galvo.c @@ -37,7 +37,7 @@ void Galvo_Init(void) revision_t revision = {.major = 1, .minor = 0, .build = 0}; Luos_CreateService(Galvo_MsgHandler, POINT_2D, "galvo", revision); - stream = Streaming_CreateChannel(stream_buf, sizeof(stream_buf), 2 * sizeof(uint16_t)); + stream = Streaming_CreateChannel(stream_buf, sizeof(stream_buf) / sizeof(stream_buf[0]), sizeof(stream_buf[0])); period = TimeOD_TimeFrom_s(1.0 / DEFAULT_SAMPLE_FREQUENCY); // Configure the trajectory samplerate at 100Hz control.flux = STOP; } diff --git a/examples/projects/product/laser/lib/laser/laser.c b/examples/projects/product/laser/lib/laser/laser.c index c5e03f15c..fa8ad7888 100644 --- a/examples/projects/product/laser/lib/laser/laser.c +++ b/examples/projects/product/laser/lib/laser/laser.c @@ -179,7 +179,7 @@ void Laser_Init(void) // Init the Luos service revision_t revision = {.major = 1, .minor = 0, .build = 0}; Luos_CreateService(Laser_MsgHandler, POWER_TYPE, "laser", revision); - stream = Streaming_CreateChannel(stream_buf, sizeof(stream_buf), sizeof(ratio_t)); + stream = Streaming_CreateChannel(stream_buf, sizeof(stream_buf) / sizeof(stream_buf[0]), sizeof(stream_buf[0])); period = TimeOD_TimeFrom_s(1.0 / DEFAULT_SAMPLE_FREQUENCY); // Configure the trajectory samplerate at 100Hz laser_control.flux = STOP; }