jpatcher_get_parentpatcher()

Jan 14, 2009 at 10:45pm

jpatcher_get_parentpatcher()

Hi all,

I’m having some trouble getting information about the parentpatcher of an object in a subpatcher.

If I have an object in a subpatcher or an abstraction and it calls jpatcher_get_parentpatcher(), I get a NULL pointer. However, if I open the subpatcher window and instantiate the object again, I get the parentpatcher’s address.

Code:

t_patcher *patcher, *ppatcher;
t_box *box;
object_obex_lookup(x, gensym(“#P”), (t_object **)&patcher);
post(“patcher address: %p”, patcher);
post(“patcher name: %s”, jpatcher_get_name(patcher)->s_name);
box = jpatcher_get_box(patcher);
post(“box = %p”, box);
ppatcher = jpatcher_get_parentpatcher(patcher);
post(“parent address: %p”, ppatcher);

Output for a normal object in the top level patcher:

patcher address: 0x18589ff0
patcher name: cmmjl_test.maxhelp
box = 0×0
parent address: 0×0

Output for an object in an abstraction called ‘abstraction’:

patcher address: 0x185a6fe0
patcher name: abstraction
box = 0×0
parent address: 0×0

Output for an object in a subpatcher called ‘foo’:

patcher address: 0x185be660
patcher name:
box = 0×0
parent address: 0×0

When I open the subpatcher called ‘foo’ and make a copy of the object with the window open, everything works fine:

patcher address: 0x185be660
patcher name: foo
box = 0x185e0bc0
parent address: 0x18589ff0

Any thoughts on this? Is it that I’m doing something wrong or is there a bug in jpatcher_get_parentpatcher()? I’d really appreciate any suggestions about how to do this properly or, if indeed it is a bug, a possible workaround.

Thanks in advance,
JM

#41685
Jan 14, 2009 at 11:03pm

On Jan 14, 2009, at 2:46 PM, John MacCallum wrote:

> I’m having some trouble getting information about the parentpatcher
> of an object in a subpatcher.

Sounds like you might be calling this in your object constructor,
before the patcher has finished loading (and before these patcher
attributes have been set). You’ll need to cache #P in your constructor
and then call after the object has been instantiated (say in loadbang,
or response to a bang message, etc.).

-Joshua

#148579
Jan 15, 2009 at 8:57pm

That was it–thanks Joshua!

JM

#148580

You must be logged in to reply to this topic.