From 7344fd54dc80d5117349b6031833b122b580d85a Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Wed, 16 Nov 2022 21:24:57 +0100 Subject: [PATCH] Fix ArtNet crash --- tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino index 701374bd1..c2620fd9d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino @@ -146,8 +146,12 @@ void ArtNetProcessPacket(uint8_t * buf, size_t len) { if (artnet_conf.matrix) { // Ws2812 led strip size_t pix_size = Ws2812StripGetPixelSize(); + // check that datalen does not exceed the number of columns + if (datalen > artnet_conf.cols * pix_size) { datalen = artnet_conf.cols * pix_size; } + // round to exact number of pixels datalen = datalen - (datalen % pix_size); + size_t offset_in_matrix = 0; if (artnet_conf.alt && (row % 2)) { for (int32_t i = idx, j = idx + datalen - pix_size; i < j; i += pix_size, j -= pix_size) { for (int32_t k = 0; k < pix_size; k++) { @@ -156,6 +160,7 @@ void ArtNetProcessPacket(uint8_t * buf, size_t len) { buf[j+k] = temp; } } + offset_in_matrix = artnet_conf.cols * pix_size - datalen; // add a potential offset if the frame is smaller than the columns } // process dimmer @@ -179,7 +184,7 @@ void ArtNetProcessPacket(uint8_t * buf, size_t len) { // process pixels size_t h_bytes = artnet_conf.cols * pix_size; // size in bytes of a single row - size_t offset_in_matrix = artnet_conf.offs * pix_size + row * h_bytes; + offset_in_matrix += artnet_conf.offs * pix_size + row * h_bytes; if (datalen > h_bytes) { datalen = h_bytes; } // copy at most one line Ws2812CopyPixels(&buf[idx], datalen, offset_in_matrix); @@ -366,6 +371,8 @@ bool ArtNetStart(void) { Settings->light_pixels = artnet_conf.rows * artnet_conf.cols + artnet_conf.offs; Settings->light_rotation = 0; Ws2812ReinitStrip(); + } else { + Ws2812Clear(); } }