Forums > Dev

max termination notification

April 8, 2012 | 7:40 pm

Is there any way to register a method, that gets called before Max quits ?
Maybe something that gets called by class_free ?

cheers,
jan.


April 9, 2012 | 10:19 am

Your Objects free() method is called before Max quits. Either do there what needs to be done or in your notify() method which for example gets called before the parent patcher window closes, which also happens before Max quits.

Have a look at the notify method in the scripto example, you have to check the msg argument and the sender.
Something like
if(msg == gensym("free"))
{
if(sender == x->myParentPatcherWindow)
{
do what needs to be done…
}
}

cheers,
Thomas


April 9, 2012 | 11:22 am

The problem with these methods is, that they also get called when Max doesn’t quit.

The reason i need this is because i have an global context variable that needs to be shared amongst instances of my object.
The context gets initialized in the class_new method.
I thought maybe there’s also a customizable class_free method, where I could close the context.

So I guess I’ll have to count the number of object instances, close the context when there are no more instances and reinitalize the context in the object’s new method.

thx anyway!


April 9, 2012 | 3:52 pm

No, that’s not the only option…

In ext_proto.h there’s a quittask_install() function prototyped.
That allows you to register a method that will be called ONLY when Max quits.
It might provide a better alternative to counting the number of object instances.

Hope this helps

- Luigi


April 9, 2012 | 10:13 pm

Many Thanks Luigi!

That’s exactly what I was looking for :)

cheers,
jan.


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