justingardner / mgl

A suite of mex/m files for displaying psychophysics stimuli
http://justingardner.net/mgl
Other
18 stars 22 forks source link

Close open mglMetal window on matlab exit #48

Closed cjoynes closed 2 years ago

cjoynes commented 2 years ago

It would be nice to have Matlab call mglClose when exiting so mglMetal isn’t open without an associated Matlab instance.

justingardner commented 2 years ago

Ben - this can be done by adding a mexAtExit function (see mglPrivateOpen.c). Perhaps in mglSocketCreateClient?

benjamin-heasly commented 2 years ago

Good call, I added a cleanup callback in e6b4b81a1a4b8f79510aa9c8a1cb8e6ecad5c189.

I'm trying a slightly different approach with an onCleanup callback.

So now mglMetalOpen stores a cleanup callback in the global mgl struct. Whenever the mgl struct gets cleared, the callback will also shut down any mglMetal process. This should happen at times like

This lets us define the cleanup handler in the same file where we're starting the mglMetal process. If one day we have multiple mglMetal processes at the same time, this should also let us manage them and clean them up individually.