[PD-dev] help coding an object, I need it cause I don't know better

Alexandre Torres Porres porres at gmail.com
Tue Oct 10 01:27:38 CEST 2023


Now, if I tried fixed what wasn't broken, then I still don't know what's
broken and let me tell what was originally not working.

The object was behaving perfectly well with two named variables, but when I
tried 3, I am getting an error when trying to free the first variable name.

This is all the same as in [value], I just have a loop to create many
variables according to the arguments, which are created in "var_get". When
it is freed, the problem I have is that it doesn't find the first created
variable with "pd_findbyclass", as if it wasn't created, but printing and
debugging, it does say and show it was in fact created...

So maybe forget about all from before as I thought I saw something weird
that could fix and looks like it's unrelated.

Em seg., 9 de out. de 2023 às 18:42, Alexandre Torres Porres <
porres at gmail.com> escreveu:

> Ok, updated the code as before, so it compiles
> https://github.com/porres/pd-else/commit/4f052fbe4af3889f06eb69c236f04eeae3555485
>
> now I initialize as  **x_fval in
> https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/var.c#L17
>
> At bangs, I get and set the value of the output atom list as
> *SETFLOAT(at+i, ***x->x_fval[i]);*
> https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/var.c#L27
>
> In the list method, I get atoms' values with **x->x_fval[i] =
> atom_getfloat(av+i); *
> https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/var.c#L36
>
> What's weird to me is now that in the 'new' method, I initialize the
> variable as
>
> *x->x_fval[i] = var_get(x->x_sym[i] = atom_getsymbol(av+i)); *
> https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/var.c#L80C9-L80C68
>
> and it works, and no need of '*' in here.. I would expect it though...
> not sure why, just feels right :)
>
> But i am just making sure now that all is ok and that my bugs are
> elsewhere. Also note I am initializing the data as x->x_fval =
> getbytes(sizeof(float) * x->x_n); in
> https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/var.c#L76
> and I free it as freebytes(x->x_fval, x->x_n * sizeof(*x->x_fval)); in
> https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/var.c#L40C5-L40C55
>
> thanks
>
> Em seg., 9 de out. de 2023 às 18:28, Alexandre Torres Porres <
> porres at gmail.com> escreveu:
>
>> Em seg., 9 de out. de 2023 às 16:37, IOhannes m zmölnig <zmoelnig at iem.at>
>> escreveu:
>>
>>> Am 9. Oktober 2023 18:22:11 MESZ schrieb Alexandre Torres Porres <
>>> porres at gmail.com>:
>>> >
>>> >*var.c:80:22: **error: **assigning to 'float' from incompatible type
>>> >'t_float *'*
>>>
>>> Well it's just what it says: you are trying to assign a `t_float*` value
>>> to a `t_float`.
>>> A `t_float` is some floating type, and it is not allowed to use it to
>>> store a pointer.
>>>
>>
>> Ok, your comment already did shed some light. And looking closely, the
>> [value] code actually uses *x_floatstar ... so let me get this straight,
>> that makes it a pointer then, so it works. Now, I'm also using the same
>> thing to create an array of values, that can be set with something like
>> x->x_fval[i]. This is where things get confusing to me. Now, in an
>> earlier version, this was working and initialized as **x_fval which then
>> it seems it is a pointer to the array of values?
>>
>> In the end, the question would be how to initialize a variable that can
>> take the pointer correctly. Was the last compilable code from
>> https://github.com/porres/pd-else/blob/cd1406cff28baf1eb056d1500fb0d62694171306/Code_source/Compiled/control/var.c
>> completely correct? I guess I got lucky then and when tried to fix what
>> wasn't broken I just ruined it. And the bugs I was trying to fix were
>> unrelated.
>>
>> Another good question would be simple online courses that could help me
>> understand things a little better :)
>>
>> thanks
>>
>>
>>> What's the question?
>>>
>>>
>>>
>>> mfg.sfg.jfd
>>> IOhannes
>>>
>>>
>>> _______________________________________________
>>> Pd-dev mailing list
>>> Pd-dev at lists.iem.at
>>> https://lists.puredata.info/listinfo/pd-dev
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20231009/bb6509ec/attachment.htm>


More information about the Pd-dev mailing list