Abort Object creation in external.
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?
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;
}
Yes, that's the way to go - but don't forget to free your object before leaving the constructor!
aa