Hi all,
trying to load abstractions into a patch dynamically from a self
written external sometimes leads to a segfault when turning on dsp
rendering.
Here is what I'm trying to do: The patch is some specialized synth
where a program change loads a predefined number of synth voices,
stored as abstractions, into a subpatcher and connects them within the
subpatcher. Connections to the outside world are done via throw~ and
catch~ within the abstractions.
When dsp is turned on all the time during this, sometimes, audio
generated in the synth voices isn't appearing at the outlets (it seems
the audio isn't integrated into the dsp path at all). All the created
objects and their connections are visible in the gui. Turning dsp off
and on makes it work, but trying to automatize it leads to the
segfaults from time to time.
I used a clock object to delay the reinitialisation of dsp rendering
which helps tremendously, but even with delaytimes of 1000-2500 ms I
sometimes run into the segfaults (and I consider this not really as a
"solution").
Below are the relevant code segments which are run within the same
function (lots of lines omitted).
I've spent lots of hours in gdb trying to chase this down but I'm at
loss here. This thing is killing me. Any help is greatly appreciated!
--
Orm
t_atom *p;
int n,m,xoffs,yoffs;
t_atom mess[5], atarget, aroute;
/* Clear the voices canvas */
if (x->x_synth_voices_canvas.a_w.w_symbol->s_thing)
typedmess(x->x_synth_voices_canvas.a_w.w_symbol->s_thing,
gensym("clear"), 0,0);
/* Load the abstractions into it */
for (n=4, xoffs=0, yoffs=0;
n>=0;
n--, xoffs++, yoffs++)
{
SETFLOAT(mess, ((xoffs*20)+500));
SETFLOAT(mess+1, ((yoffs*20)+50));
/* "catch-vu.pd" */
SETSYMBOL(mess+2, gensym("catch-vu"));
SETFLOAT(mess+3, x->x_canvasdollarzero);
SETFLOAT(mess+4, (float)n);
if (x->x_synth_voices_canvas.a_w.w_symbol->s_thing)
typedmess(x->x_synth_voices_canvas.a_w.w_symbol->s_thing,
gensym("obj"), 5, mess);
else {
error("synth_voices_canvas doesn't exist");
goto exit;
}
}
p=x->x_initseq->b_vec; /* this variable holds the number of voices */
for (n=1, xoffs=0, yoffs=0;
n<=(int)p->a_w.w_float;
n++, xoffs++, yoffs++)
{
SETFLOAT(mess, (((xoffs%3)*120)+50));
SETFLOAT(mess+1, ((floor((yoffs)/3)*30)+200));
/* "rec-voice.pd" */
SETSYMBOL(mess+2, gensym("rec-voice"));
SETFLOAT(mess+3, x->x_canvasdollarzero);
SETFLOAT(mess+4, (float)n);
if (x->x_synth_voices_canvas.a_w.w_symbol->s_thing)
typedmess(x->x_synth_voices_canvas.a_w.w_symbol->s_thing,
gensym("obj"), 5, mess);
else {
error("synth_voices_canvas doesn't exist");
goto exit;
}
/* connect the catch-vu objects with the rec-voices */
SETFLOAT(mess+1, 0);
SETFLOAT(mess+2, (n+4));
for (m=0;m<5;m++)
{
SETFLOAT(mess, m);
SETFLOAT(mess+3, m);
if (x->x_synth_voices_canvas.a_w.w_symbol->s_thing)
typedmess(x->x_synth_voices_canvas.a_w.w_symbol->s_thing,
gensym("connect"), 4, mess);
else {
error("synth_voices_canvas doesn't exist");
goto exit;
}
}
}
/* Turn on dsp with a delay */
clock_delay(x->x_dspclock, 500);
return;