I'm pretty sure it's because x_blksize is 0. (Internally, getbytes()
always allocates at least 1 byte, which explains why you can
successfully access the first sample.)
In the new routine, I allocate memory likes this:
In the new routine, you may only allocate the vectors that hold the
input and output signals (t_sample **), as the number of channels won't
change (well, unless you are creating a multi-channel object).
However, if you try to allocate buffers to cache the inputs, you can
only do that in the "dsp" method, as this is the place where you know
the actual blocksize.
I'm not really sure what you're trying to do. "x_in" and "x_out" are of
type "t_sample **", so I would assume that they are supposed to hold the
input/output signal vectors. However, then you allocate actual signal
buffers for each channel which makes no sense to me. If you want to save
the inputs, this would have to be *another* buffer. (Ideally, you would
save all input signals in a single continuous buffer for better cache
utilization.) There is (almost) never be a need to buffer the outputs*).
---
BTW, instead of posting code snippets, it would be more helpful to post
(a link) to the whole source code, so we can get a better picture of
what you're trying to do.
Christof
*) the only exception I can think of is when you use a library that uses
a fixed floating point precision that does not match Pd's own precision.
For example, I need to do this in my [vstplugin~] object, so it can use
single-precision-only VST plugins in a double-precision Pd.
On 22.09.2023 12:32, Alexandros Drymonitis wrote:
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
Pd-dev@lists.iem.at
https://lists.puredata.info/listinfo/pd-dev
_______________________________________________
Pd-dev mailing list
Pd-dev@lists.iem.at
https://lists.puredata.info/listinfo/pd-dev