I'm trying to code an object with a variable number of inlets and outlets, that's more complex than the one I posted a few days ago. Writing to its input works fine, but when I try to write to its output, Pd crashes. The culprit is when I try to access each individual output.

In the new routine, I allocate memory likes this:

```
x->x_in = (t_sample **)getbytes(ninlets * sizeof(t_sample *));
x->x_out = (t_sample **)getbytes(noutlets * sizeof(t_sample *));
for (i = 0; i < ninlets; i++)
    x->x_in[i] = (t_sample *)getbytes(x->x_blksize * sizeof(t_sample));
for (i = 0; i < noutlets; i++)
    x->x_out[i] = (t_sample *)getbytes(x->x_blksize * sizeof(t_sample));
```

But Pd crashes when I try to access any output other that x->x_out[0][0]. In a function that is called by the perform routine, I do the following:

```
for (i = 0; i < x->x_noutlets; i++) {
    x->x_out[i][x->x_sample_index] = (t_sample)x->x_outvec[i];
}
```

and Pd crashes. Debugging with gdb pointed to this line. Changing the code to x->x_out[0][0] does not crash Pd. I have also confirmed that x->x_outvec[i] is not crashing Pd.

Since memory for x->x_out has been allocated, and since I'm not trying to access an element beyond this allocated memory (which is also confirmed), why does Pd crash? Or am I doing something wrong in the memory allocation part?




_______________________________________________
Pd-dev mailing list
[email protected]
https://lists.puredata.info/listinfo/pd-dev

Reply via email to