Skip to content

Commit

Permalink
More robust Faust_Ctor in SuperCollider architecture file.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Dec 15, 2016
1 parent 13408d9 commit 413ff48
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions architecture/supercollider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ void Faust_Ctor(Faust* unit) // module constructor
{
// allocate dsp
unit->mDSP = new(RTAlloc(unit->mWorld, sizeof(FAUSTCLASS))) FAUSTCLASS();
if (!unit->mDSP) {
Print("Faust_Ctor: RT memory allocation failed for unit->mDSP\n");
return;
}

// init dsp
unit->mDSP->instanceInit((int)SAMPLERATE);
Expand Down Expand Up @@ -398,12 +402,24 @@ void Faust_Ctor(Faust* unit) // module constructor
SETCALC(Faust_next);
} else {
unit->mInBufCopy = (float**)RTAlloc(unit->mWorld, unit->getNumAudioInputs()*sizeof(float*));
if (!unit->mInBufCopy) {
Print("Faust_Ctor: RT memory allocation failed for unit->mInBufCopy\n");

This comment has been minimized.

Copy link
@nhthn

nhthn Dec 16, 2016

Might be better to provide the name of the UGen so the source of the error is more obvious. Also, I suggest adding the text "Try increasing the real-time memory size in the server options."

return;

This comment has been minimized.

Copy link
@nhthn

nhthn Dec 16, 2016

Pre-return you will want to SETCALC(ClearUnitOutputs). Otherwise your calculation function is NULL, which crashes the server.

}
// Allocate memory for input buffer copies (numInputs * bufLength)
// and linear interpolation state (numInputs)
// = numInputs * (bufLength + 1)
unit->mInBufValue = (float*)RTAlloc(unit->mWorld, unit->getNumAudioInputs()*sizeof(float));
if (!unit->mInBufValue) {
Print("Faust_Ctor: RT memory allocation failed for unit->mInBufValue\n");
return;
}
// Aquire memory for interpolator state.
float* mem = (float*)RTAlloc(unit->mWorld, unit->getNumAudioInputs()*BUFLENGTH*sizeof(float));
if (mem) {
Print("Faust_Ctor: RT memory allocation failed for mem\n");
return;
}
for (int i=0; i < unit->getNumAudioInputs(); ++i) {
// Initialize interpolator.
unit->mInBufValue[i] = IN0(i);
Expand Down Expand Up @@ -431,6 +447,9 @@ void Faust_Ctor(Faust* unit) // module constructor
Print(" Generating silence ...\n");
SETCALC(Faust_next_clear);
}

// Fix for https://github.com/grame-cncm/faust/issues/13
ClearUnitOutputs(unit, 1);

This comment has been minimized.

Copy link
@nhthn

nhthn Dec 16, 2016

This should be moved up so that it comes before any possible return statements.

}

void Faust_Dtor(Faust* unit) // module destructor
Expand Down

3 comments on commit 413ff48

@sletz
Copy link
Member Author

@sletz sletz commented on 413ff48 Dec 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source file use here : https://github.com/grame-cncm/faust/blob/master-dev/architecture/supercollider.cpp

Since I'm not a SuperCollider expert at all, it would be much easier if you could directly correct our supercollider.cpp architecture file, and do a merge request? (even "blind" changes would be OK, I can test the result before merging)
Thanks in advance.

@nhthn
Copy link

@nhthn nhthn commented on 413ff48 Dec 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry! I realize that what I'm doing here is kind of inconsiderate. I'll file a PR soon.

@sletz
Copy link
Member Author

@sletz sletz commented on 413ff48 Dec 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may check this commit 073a90e

Please sign in to comment.