[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] Fun crucial gui problem vs. SwingOSC

More of an FYI, I suppose -- not sure exactly what to do with this. Maybe it's sufficient to document in crucial's GUI API help files, or maybe it needs a code fix. I was able to work around it pretty easily in my library classes so it's not a huge deal.

The FlowView and MultiPageLayout classes in crucial allow objects to be added as "remove on close" references. When the window closes, the flow view calls 'remove' on each of these objects in turn. Another method, viewDidClose, clears references so that the GUI object will no longer be valid.

This is all fine in cocoa because the remove on close part is synchronous -- the sequence of events is to remove all the remove on close objects, then call viewDidClose. In SwingOSC, it seems that the remove on close part is deferred, and it runs after viewDidClose.

In most cases this isn't a problem, but sometimes there are some other resources involved (routines, synths on the server, etc.). For example, I found this in my mixer channel scope objects. Calling 'scope" on the mixer channel creates a MixerScope object that creates a buffer and runs a scope synth. It also creates a MixerScopeGui that registers in the parent flow view for removal on close. When the window is closed, the MixerScopeGui should call back to its model (the MixerScope) to free the synth and buffer. In SwingOSC (well, until I checked in a fix to my code), viewDidClose runs first, clearing the model instance variable. Then, when it's time to remove the GUI object, model is empty and it has no idea to whom to call back. So the buffer and synth remain on the server, even though they aren't doing anything.

I worked around it by having a separate instance variable, myModel, that viewDidClose doesn't know about.

It took me quite some time yesterday morning to find this, so at the very least I'd like to add a note to crucial's object GUI documentation (with permission of course). As for a transparent fix, no idea. I haven't had time to dig into the SwingOSC code to find out what it's doing when a window closes.


: H. James Harkins

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman