Now I realize that everything I posted in the last post makes
absolutely no sense at all. Something else is causing the crashes.
Damn!
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 the XXX_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 whatever w[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
_______________________________________________ Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list