[PD] variable outlets in dsp object

David Medine dmedine at ucsd.edu
Thu Jun 8 10:51:59 CEST 2017


I am writing a DSP extern that can have a any number of outlets 
depending on the creation arguments (like [fexpr~], e.g.). In order to 
interact with the outlets in the XXX_tilde_perform loop, I made a member 
of my t_XXX_tilde data structure thus:

t_sample **lcl_outs;

Then, when I know how many outlets I need, I allocate the appropriate 
amount of memory. In theXXX_tilde_perform loop, I set the pointers to 
those handed by Pd's scheduling engine in the standard way:

for(int i=0;i<x->nouts;i++)

     x->lcl_outs[i] = w[2+i];

I found that this would sporadically crash Pd when turning the DSP 
engine on and off and (sometimes) when connecting/disconnecting to one 
of the outlets. I think that I have solved this problem by copying my 
pointers at the head of the XXX_tilde_perform method to a local variable:

t_sample **lcl_outs = x->lcl_outs;

for(int i=0;i<x->nouts;i++)

     lcl_outs[i] = w[2+i];

Everything /appears/ to work now. I assume that somehow Pd's engine is 
rubbing my x->lcl_outs ptr off of the stack. Thus, by copying it to 
another ptr I avoid this problem because my OS still knows where the 
allocated memory is. That is to say, when Pd gets rid of whateverw[2] 
is, it then removes the ptr lcl_outs, not x->lcl_outs, which still has 
memory behind it.

Am I reading this right? I am not at all confident that I have truly 
solved this problem. If anyone has any insight, I'd like to know too.

Thanks!

David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20170608/13754a8e/attachment.html>


More information about the Pd-list mailing list