MaltWhiskey
Active member
I made a new animation for my led cube, but it kept crashing while I could not find an error. After putting printf everywhere and commenting out lines it looks like writing to the brighten array, modifies the running code and makes it crash. But I never go above the allowed boundaries.
So I copied the brighten line and added this safety buffer:
bool brighten11111[display.width][display.height][display.depth] = {};
now it works fine.
The code below is not checked in until I fix it, but it's part of my led cube frame work: https://github.com/MaltWhiskey/Mega-Cube
So if more code is needed it may be there...
Can anybody spot a mistake here?
So I copied the brighten line and added this safety buffer:
bool brighten11111[display.width][display.height][display.depth] = {};
now it works fine.
The code below is not checked in until I fix it, but it's part of my led cube frame work: https://github.com/MaltWhiskey/Mega-Cube
So if more code is needed it may be there...
Can anybody spot a mistake here?
Code:
#ifndef TWINKELS_H
#define TWINKELS_H
#include <stdint.h>
#include "Animation.h"
#include "Math8.h"
class Twinkels : public Animation {
private:
Timer timer = 10.0f;
uint8_t pixel_density = 100;
uint8_t fade_in_speed = 1;
uint8_t fade_out_speed = 1;
// keep source color for the display to prevent scaling errors
Color colors[display.width][display.height][display.depth] = {};
// amount the source is scaled 0 to 255
uint8_t scaling[display.width][display.height][display.depth] = {};
// the source is scaled from black to color or color to black
bool brighten[display.width][display.height][display.depth] = {};
bool brighten11111[display.width][display.height][display.depth] = {};
private:
void randomize() { timer = noise.nextRandom(5.00f, 10.00f); }
bool draw(float dt) {
for (uint8_t x = 0; x < display.width; x++) {
for (uint8_t y = 0; y < display.height; y++) {
for (uint8_t z = 0; z < display.depth; z++) {
if (brighten[x][y][z]) {
scaling[x][y][z] = qadd8(scaling[x][y][z], fade_in_speed);
if (scaling[x][y][z] == 255) brighten[x][y][z] = false;
} else {
scaling[x][y][z] = qsub8(scaling[x][y][z], fade_out_speed);
}
Color c = colors[x][y][z];
display.color(x, y, z) = c.scale(scaling[x][y][z]);
}
}
}
// Consider adding a new random twinkle
if (random(0, 256) < pixel_density) {
uint8_t x = random(0, display.width);
uint8_t y = random(0, display.height);
uint8_t z = random(0, display.depth);
colors[x][y][z] = Color(0, 255);
brighten[x][y][z] = true;
scaling[x][y][z] = 0;
}
return (timer.update());
}
};
#endif
Last edited by a moderator: