Skip to content

Commit 4fd1b39

Browse files
committed
Bugfix in Aurora FX and fixed compiler warning in PS Impact
1 parent e2f5bec commit 4fd1b39

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

wled00/FX.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4766,30 +4766,17 @@ class AuroraWave {
47664766
};
47674767

47684768
uint16_t mode_aurora(void) {
4769-
//aux1 = Wavecount
4770-
//aux2 = Intensity in last loop
4771-
47724769
AuroraWave* waves;
4770+
SEGENV.aux1 = map(SEGMENT.intensity, 0, 255, 2, W_MAX_COUNT); // aux1 = Wavecount
4771+
if(!SEGENV.allocateData(sizeof(AuroraWave) * SEGENV.aux1)) { // 20 on ESP32, 9 on ESP8266
4772+
return mode_static(); //allocation failed
4773+
}
4774+
waves = reinterpret_cast<AuroraWave*>(SEGENV.data);
47734775

4774-
//TODO: I am not sure this is a correct way of handling memory allocation since if it fails on 1st run
4775-
// it will display static effect but on second run it may crash ESP since data will be nullptr
4776-
4777-
if(SEGENV.aux0 != SEGMENT.intensity || SEGENV.call == 0) {
4778-
//Intensity slider changed or first call
4779-
SEGENV.aux1 = map(SEGMENT.intensity, 0, 255, 2, W_MAX_COUNT);
4780-
SEGENV.aux0 = SEGMENT.intensity;
4781-
4782-
if(!SEGENV.allocateData(sizeof(AuroraWave) * SEGENV.aux1)) { // 26 on 32 segment ESP32, 9 on 16 segment ESP8266
4783-
return mode_static(); //allocation failed
4784-
}
4785-
4786-
waves = reinterpret_cast<AuroraWave*>(SEGENV.data);
4787-
4776+
if(SEGENV.call == 0) {
47884777
for (int i = 0; i < SEGENV.aux1; i++) {
47894778
waves[i].init(SEGLEN, CRGB(SEGMENT.color_from_palette(hw_random8(), false, false, hw_random8(0, 3))));
47904779
}
4791-
} else {
4792-
waves = reinterpret_cast<AuroraWave*>(SEGENV.data);
47934780
}
47944781

47954782
for (int i = 0; i < SEGENV.aux1; i++) {
@@ -8495,7 +8482,6 @@ static const char _data_FX_MODE_PARTICLEPERLIN[] PROGMEM = "PS Fuzzy Noise@Speed
84958482
#define NUMBEROFSOURCES 8
84968483
uint16_t mode_particleimpact(void) {
84978484
ParticleSystem2D *PartSys = nullptr;
8498-
uint32_t i = 0;
84998485
uint32_t numMeteors;
85008486
PSsettings2D meteorsettings;
85018487
meteorsettings.asByte = 0b00101000; // PS settings for meteors: bounceY and gravity enabled
@@ -8530,7 +8516,7 @@ uint16_t mode_particleimpact(void) {
85308516
numMeteors = min(PartSys->numSources, (uint32_t)NUMBEROFSOURCES);
85318517
uint32_t emitparticles; // number of particles to emit for each rocket's state
85328518

8533-
for (i = 0; i < numMeteors; i++) {
8519+
for (uint32_t i = 0; i < numMeteors; i++) {
85348520
// determine meteor state by its speed:
85358521
if ( PartSys->sources[i].source.vy < 0) // moving down, emit sparks
85368522
emitparticles = 1;
@@ -8546,7 +8532,7 @@ uint16_t mode_particleimpact(void) {
85468532
}
85478533

85488534
// update the meteors, set the speed state
8549-
for (i = 0; i < numMeteors; i++) {
8535+
for (uint32_t i = 0; i < numMeteors; i++) {
85508536
if (PartSys->sources[i].source.ttl) {
85518537
PartSys->sources[i].source.ttl--; // note: this saves an if statement, but moving down particles age twice
85528538
if (PartSys->sources[i].source.vy < 0) { // move down

0 commit comments

Comments
 (0)