Make ws2812 and apa102 responsibly only for their own buffers

This fixes a bug where delete[] would be called on a bytearray buffer allocated by MicroPython on gc_heap.
pull/194/head
Phil Howard 2021-08-25 21:57:00 +01:00
rodzic 5abdad05a8
commit e283d460d4
4 zmienionych plików z 12 dodań i 2 usunięć

Wyświetl plik

@ -34,6 +34,7 @@ APA102::APA102(uint num_leds, PIO pio, uint sm, uint pin_dat, uint pin_clk, uint
if(this->buffer == nullptr) {
this->buffer = new RGB[num_leds];
managed_buffer = true;
}
}

Wyświetl plik

@ -66,7 +66,10 @@ namespace plasma {
// pio_sm_unclaim seems to hardfault in MicroPython
pio_sm_unclaim(pio, sm);
#endif
delete[] buffer;
if(managed_buffer) {
// Only delete buffers we have allocated ourselves.
delete[] buffer;
}
}
bool start(uint fps=60);
bool stop();
@ -86,5 +89,6 @@ namespace plasma {
uint pio_program_offset;
int dma_channel;
struct repeating_timer timer;
bool managed_buffer = false;
};
}

Wyświetl plik

@ -33,6 +33,7 @@ WS2812::WS2812(uint num_leds, PIO pio, uint sm, uint pin, uint freq, bool rgbw,
if(!this->buffer) {
this->buffer = new RGB[num_leds];
managed_buffer = true;
}
}

Wyświetl plik

@ -75,7 +75,10 @@ namespace plasma {
// pio_sm_unclaim seems to hardfault in MicroPython
pio_sm_unclaim(pio, sm);
#endif
delete[] buffer;
if(managed_buffer) {
// Only delete buffers we have allocated ourselves.
delete[] buffer;
}
}
bool start(uint fps=60);
bool stop();
@ -95,5 +98,6 @@ namespace plasma {
uint pio_program_offset;
int dma_channel;
struct repeating_timer timer;
bool managed_buffer = false;
};
}