[PD-dev] Object crashes when trying to write to its outlet

Alexandros Drymonitis adrcki at gmail.com
Sat Sep 23 08:54:16 CEST 2023


On 9/22/23 14:26, Christof Ressi wrote:
> 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.

I'm aware of that, but it's a rather big project, around 5000 lines, and 
I haven't published it yet. It's based on [neuralnet], which is hosted 
here https://github.com/alexdrymonitis/neuralnet. I'm trying to create a 
signal version of this object. The control object takes lists of data, 
but the signal will have to take signals, therefore it must have a 
variable number of inlets and outlets, depending on the network 
structure. I could go with multichannel signals, but trying to code a 
simple external a few days ago, didn't get me very far.

It's in my plans, once I get this variable I/O sorted,to add the 
possibility to pack signals to a multichannel inlet or outlet, but 
that's for a later stage.

> 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.)
x_blksize is not 0, it gets the value returned from sys_getblksize(). It 
is also updated in the dsp routine, in case the block size changes, 
where I resize the bytes of the inlets and outlets with resizebytes().
>
>> 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).

So you're saying that I only need to do the initial allocation, like this:

`x->x_in = (t_sample **)getbytes(ninlets * sizeof(t_sample *));`

and not try to allocate `t_sample *` bytes in the for loop? I did try 
this, but again the object is crushing.

What I'm trying to do is get the input signals, copy them to a t_atom 
vector, process the input (it's a neural network object), and then copy 
the processed data which is stored in a *t_float, to the outlets of the 
object.

To do this, in the perform routine, I run the following loop:

```
for (i = 0; i < n; i++) {
     for (j = 0; j < ninlets; j++) {
         x->x_input[0][j] = x->x_in[j][i];
     }
     x->x_sample_index = i;
     forward_pass(x);
}
```

`n` is the block size. Then `forward_pass()` ends up in what I posted in 
the OP. Here it is again:

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

In my understanding, if the necessary allocated memory for the outlets 
has indeed been allocated, why would this crash?

> 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.
I guess it doesn't make sense to someone who knows C and the Pd API very 
well, but I'm not one of them :) I've coded a few externals, but this 
one is more complex and I'm trying to get my head around this.






More information about the Pd-dev mailing list