Forums > Dev

Using binbuf_totext to read patcher contents

March 5, 2007 | 8:07 pm

Hi,

I am trying to work out how to display the contents of an external’s containing
patch as text. So far I have:

void *test_new (float n){
t_test *x;
char **buf_text = newhandle(0);
long buf_size;
char rv;

x = (t_test *)newobject(test_class);
x->patcher = ((t_symbol *)gensym("#P"))->s_thing;

if(x->patcher){
if(ispatcher (x->patcher))
rv = binbuf_totext (((t_patcher *)x->patcher)->p_box->b_binbuf, buf_text,
&buf_size);
}

return (x);
}

This just crashes Max when the external is loaded. The test ispatcher() succeeds,
but the call to binbuf_totext() results in a memory fault ‘KERN_INVALID_ADDRESS’.

Anyone got an idea what could be wrong?

Jamie


March 6, 2007 | 1:27 am

Just off the top of my head, but I had some problems with the
line-length in the binbufs, but I think that was on the writing
side of things.

brad

http://music.columbia.edu/~brad

Quoting Jamie Bullock :

>
> Hi,
>
> I am trying to work out how to display the contents of an
> external’s containing
> patch as text. So far I have:
>
> void *test_new (float n){
> t_test *x;
> char **buf_text = newhandle(0);
> long buf_size;
> char rv;
>
> x = (t_test *)newobject(test_class);
> x->patcher = ((t_symbol *)gensym("#P"))->s_thing;
>
> if(x->patcher){
> if(ispatcher (x->patcher))
> rv = binbuf_totext (((t_patcher
> *)x->patcher)->p_box->b_binbuf, buf_text,
> &buf_size);
> }
>
> return (x);
> }
>
> This just crashes Max when the external is loaded. The test
> ispatcher() succeeds,
> but the call to binbuf_totext() results in a memory fault
> ‘KERN_INVALID_ADDRESS’.
>
> Anyone got an idea what could be wrong?
>
> Jamie
>


March 8, 2007 | 9:22 am

Hi Jamie,

I was looking through some code and I got the binbuf for a patch like this:

mess1((Object *)p,gensym("save"),bb);

where p is a valid pointer to a patcher object
bb is a binbuf obtained via binbuf_new()

perhaps try binbuf_totext() on this binbuf
and maybe initialise your buf_size variable to 0 before calling it.

Martin


March 8, 2007 | 6:41 pm

Hi Martin,

On Thu Mar 8 9:22 , Martin Robinson sent:

>I was looking through some code and I got the binbuf for a patch like this:
>
>mess1((Object *)p,gensym("save"),bb);
>

Thanks, that works like a charm! It just took me a few attempts to work out that
the call to the mess1() macro needs to be made after the class has been
instantiated i.e. outside of test_new().

Jamie


March 12, 2007 | 7:22 am

Yes, I seem to call discovering (after many crashes) that the binbuf stored in a box/patcher is not often valid. But sending the "save" message should work since I guessed that’s how Max gets the binbuf when it saves your patch.

The code I got this from was an object I made a few years ago called teleport which converted the enclosing patcher to binbuf/text then transmitted it via OSC and rebuilt the patch at he other end (including performing a loadbang).


Viewing 5 posts - 1 through 5 (of 5 total)