Forums > MaxMSP

Abort Object creation in external.

March 10, 2014 | 2:33 am

Hi,

I’m used to program pd externals with flext. Now I have to use the MAX C-API to program Max externals.

In flext, there was the function InitProblem();, which I used to abort object creation in the constructor for instance if the user set the wrong creation arguments. Pd printed a message like "Object, couldn’t create." automatically.

Is there something similar in Max?


March 11, 2014 | 6:32 am

Here is my solution: I abort object creation by returning a NULL pointer and printing an error message to Max console.

void *fooModule_new(t_symbol *s, long argc, t_atom *argv)
{
    t_fooModule *x = (t_fooModule *) object_alloc(fooModule_class);
    t_pfftpub *pfft = (t_pfftpub*) gensym("__pfft~__")->s_thing;

    if (pfft->x_fullspect == 0)
    {
        object_error((t_object *) x, "Full spectrum flag in pfft~ must be 1!");
        return NULL;
    }

    /* some other code here .... */

    return x;
}

March 11, 2014 | 7:30 am

Yes, that’s the way to go – but don’t forget to free your object before leaving the constructor!
aa


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