BelaPlatform / supercollider

an environment and programming language for real time audio synthesis and algorithmic composition
GNU General Public License v3.0
14 stars 8 forks source link

UGens which detect invalid settings at constructor should still call SETCALC() #79

Closed giuliomoro closed 3 years ago

giuliomoro commented 3 years ago

or they'll segfault.

This is stated, e.g.: here. The current behaviour of all the analog Bela UGens and some of the digital ones is that if there is some invalid setting at Ctor, SETCALC() is never called, so it will then segfault in SC_Graph.cpp when

void Graph_Calc_unit(Unit* unit) { (unit->mCalcFunc)(unit, unit->mBufLength); }

is called.

There is something else about initialising the output value (i.e.: what is the first output to output?), which is a discussion started at the issue above and continued here. This is less crucial in a way (no crash, at most a click at startup).

giuliomoro commented 3 years ago

@brianlheim what is a good way (if any) for a UGen to remove itself from the processing graph (e.g.: when an invalid setting is detected and there is no point in keep calling the callback)? I see things like Unit_DoneAction or Unit_EndCalc or Unit::mDone, but it seems like the former is never called and the latter is never checked ...

mossheim commented 3 years ago

i am not an expert by any means, but it looks like most UGens which fail to properly initialize set their calc function as ClearUnitOutputs: https://github.com/supercollider/supercollider/blob/develop/server/plugins/FFT_UGens.cpp#L175

giuliomoro commented 3 years ago

yes that's what I had observed, too ... I will try to ask on the supercollider GH, thanks

giuliomoro commented 3 years ago

c6b8024d6289accbfa4ce2e46b59aecb2497d424 will take care of this, but currently it is just a draft. Will amend and rebase tomorrow I think