typedmess crash. MAX 6.1.5. windows 64bit

    Jan 09 2014 | 9:07 am
    im using Visual Studio 2013, 64bit for external compilation. I compile the iterate2 example with some modification (see below). Max crashs when i send
    typedmess(obj, gensym("set"), 1, sendargs);
    to a messagebox with the varname "parsnip". The same code works fine for MAX5.x on windows or for MAX6.1.x on Mac.
    Are there workarounds for this bug? Thanks Thomas
    long iterate2_callback(t_iterate2 *x, t_object *obj) { t_rect jr; t_object *p; t_symbol *s;
    // modification: t_atom sendargs[1]; t_symbol *foundname = object_attr_getsym(obj, gensym("varname"));
    jbox_get_patching_rect(obj, &jr); p = jbox_get_patcher(obj); s = jpatcher_get_name(p); object_post((t_object *)x, "in %s, box @ x %ld y %ld, w %ld, h %ld", s->s_name, (long)jr.x, (long)jr.y, (long)jr.width, (long)jr.height);
    // modification: if (!strcmp(foundname->s_name, "parsnip")){ atom_setsym(sendargs, gensym("foo"); typedmess(obj, gensym("set"), 1, sendargs); }
    return 0; }

    • Jan 15 2014 | 2:10 am
      Just to confirm... without your modifications the example works properly?
    • Jan 15 2014 | 7:22 pm
      Hi Timothy,
      yes, the examples themselves work fine. The problem is just that MAX crashs if i try t send a message, specially one with a symbol to obj. In my patch, i have a message box with varname "parsnip" so this code would just send the message to this object - just to be sure.
      Thanks for help! Thomas
    • Jan 16 2014 | 10:05 am
      Hi there,
      I am not sure this will actually solve your problem because I am not using Visual Studio or Windows, however these are the only changes that I would suggest. It might be worth a try...
      Assuming you iterate with the following code: void iterate2_bang(t_iterate2 *x) { t_object *jp; t_max_err err; long result = 0; err = object_obex_lookup(x, gensym("#P"), (t_object **)&jp); if (err != MAX_ERR_NONE) { return; } object_method(jp, gensym("iterate"), (method)iterate2_callback, x, PI_DEEP | PI_WANTBOX, &result); }
      ...then change your callback to this:
      long iterate2_callback(t_iterate2 *x, t_object *box) { t_rect rect; t_object *patcher; t_symbol *patchername; t_symbol *classname; // modification: t_atom sendargs[1]; t_symbol *foundname = jbox_get_varname(box); jbox_get_patching_rect(box, &rect); patcher = jbox_get_patcher(box); patchername = jpatcher_get_name(patcher); classname = object_classname(jbox_get_object(box)); object_post((t_object *)x, "in %s, obj %s @ x %ld y %ld, width %ld, height %ld", patchername->s_name, classname->s_name, (long)rect.x, (long)rect.y, (long)rect.width, (long)rect.height); // modification: #if 1 if (foundname == gensym("parsnip")) { atom_setsym(sendargs, gensym("foo")); typedmess(jbox_get_object(box), gensym("set"), 1, sendargs); } #else if (foundname == gensym("parsnip")) { t_atom rv; atom_setsym(sendargs, gensym("foo")); object_method_typed(jbox_get_object(box), gensym("set"), 1, sendargs, &rv); } #endif return 0; }
      Try both ways [using typedmess() and object_method_typed()] and see if there's a difference.
      I'd be curious to see if it works now... Hope it helps.
      - Luigi
    • Jan 16 2014 | 11:33 am
      One thing I see in your code is that there is no handling for what happens if there is an error or unexpected result. For example, you have this code:
      t_symbol *foundname = object_attr_getsym(obj, gensym(“varname”));
      and then this code:
      if (!strcmp(foundname->s_name, “parsnip”)){
      What happens if the call to object_attr_getsym() fails? If foundname is NULL then dereferencing the pointer will certainly. However, you indicated that you think the crash is in the call to typedmess(). Can you give some more background as to why? Have you checked that the "obj" pointer is legit?
      A final question that would help us to help you... The help patchers specifies "Max 6.1.4 Win 64bit" and the title of the forum post says "6.1.5 Win 64 bit". Have you tried this with Win 32-bit?
    • Jan 16 2014 | 6:53 pm
      Hi Luigi,
      no, i tried. This crashs too.
      Thanks anyway Thomas
    • Jan 16 2014 | 7:16 pm
      Hi Timothy,
      on all other platforms iterate2 with this modification works (win: 32 bit no problem, mac: no problem). The goal is to send messages to objects which were found by their varname.
      It can't be a null pointer problem of *foundname, because it only crashs if i send something to obj.
      I attach the whole code of the modified iterate2.
      Anyway my MAX object is another one (the conTimbre_eplayer.mxo), where i first found this bug when porting code to windows version. I only tried with the official iterate2 example to be sure about the bug.
      Thank you for help Thomas