Skip to content

Commit 8aeb9e1

Browse files
committed
bugfix in PS pointer alignment
- bug was leading to crashes when heap is low
1 parent cfad0b8 commit 8aeb9e1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

wled00/FXparticleSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ bool initParticleSystem2D(ParticleSystem2D *&PartSys, uint32_t requestedsources,
11181118
allocsuccess = true;
11191119
break; // allocation succeeded
11201120
}
1121-
numparticles /= 2; // cut number of particles in half and try again
1121+
numparticles = ((numparticles / 2) + 3) & ~0x03; // cut number of particles in half and try again, must be 4 byte aligned
11221122
PSPRINTLN(F("PS 2D alloc failed, trying with less particles..."));
11231123
}
11241124
if (!allocsuccess) {
@@ -1815,7 +1815,7 @@ bool initParticleSystem1D(ParticleSystem1D *&PartSys, const uint32_t requestedso
18151815
allocsuccess = true;
18161816
break; // allocation succeeded
18171817
}
1818-
numparticles /= 2; // cut number of particles in half and try again
1818+
numparticles = ((numparticles / 2) + 3) & ~0x03; // cut number of particles in half and try again, must be 4 byte aligned
18191819
PSPRINTLN(F("PS 1D alloc failed, trying with less particles..."));
18201820
}
18211821
if (!allocsuccess) {

0 commit comments

Comments
 (0)