Skip to content

Commit 4711fb0

Browse files
author
Nathan Ho
committed
AnalogEcho: explain the RTAlloc check and add a return
1 parent 4fe1572 commit 4711fb0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

03-AnalogEcho/AnalogEcho.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ void AnalogEcho_Ctor(AnalogEcho* unit) {
4343
// Allocate the buffer. Do NOT use malloc!
4444
// SuperCollider provides special real-time-safe allocation and freeing functions.
4545
unit->buf = (float*)RTAlloc(unit->mWorld, unit->bufsize * sizeof(float));
46+
47+
// This check makes sure that RTAlloc succeeded. (It might fail if there's not enough memory.)
48+
// If you don't do this check properly then YOU CAN CRASH THE SERVER!
49+
// A lot of ugens in core and sc3-plugins fail to do this. Don't follow their example.
4650
if (unit->buf == NULL) {
51+
// Avoid retaining AnalogEcho_next as the calculation function.
4752
SETCALC(ft->fClearUnitOutputs);
4853
ClearUnitOutputs(unit, 1);
4954

5055
if(unit->mWorld->mVerbosity > -2) {
5156
Print("Failed to allocate memory for AnalogEcho ugen.\n");
5257
}
58+
59+
return;
5360
}
61+
5462
// Fill the buffer with zeros.
5563
memset(unit->buf, 0, unit->bufsize * sizeof(float));
5664

0 commit comments

Comments
 (0)