Update of /cvsroot/audacity/audacity-src/src/effects/audiounits
In directory 
23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15903/src/effects/audiounits

Modified Files:
        AudioUnitEffect.cpp 
Log Message:
Fix crash at Audacity termination if user clicks the window close button (X).  
Dialog would be deleted, but wxWidgets didn't know about it so it tried to get 
rid of it again at termination.

Index: AudioUnitEffect.cpp
===================================================================
RCS file: 
/cvsroot/audacity/audacity-src/src/effects/audiounits/AudioUnitEffect.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- AudioUnitEffect.cpp 15 Aug 2009 10:09:47 -0000      1.17
+++ AudioUnitEffect.cpp 14 Nov 2009 10:10:07 -0000      1.18
@@ -71,6 +71,9 @@
                    AudioUnit unit,
                    AudioUnitCarbonView carbonView,
                    Effect *effect);
+   virtual ~AudioUnitDialog();
+
+   void RemoveHandler();
 
    void OnOK(wxCommandEvent &event);
    void OnCancel(wxCommandEvent &event);
@@ -82,7 +85,8 @@
    wxBoxSizer           *mMainSizer;
    Effect               *mEffect;
 
-   EventHandlerRef       mEventHandlerRef;
+   EventHandlerRef       mHandlerRef;
+   EventHandlerUPP       mHandlerUPP;
 
    DECLARE_EVENT_TABLE()
 };
@@ -723,6 +727,28 @@
 // AudioUnitDialog methods
 //
 
+// Event handler to capture the window close event
+static const EventTypeSpec eventList[] =
+{
+   {kEventClassWindow, kEventWindowClose},
+};
+
+static pascal OSStatus EventHandler(EventHandlerCallRef handler, EventRef 
event, void *data)
+{
+   OSStatus result = eventNotHandledErr;
+
+   AudioUnitDialog *dlg = (AudioUnitDialog *)data;
+
+   if (GetEventClass(event) == kEventClassWindow && GetEventKind(event) == 
kEventWindowClose) {
+      dlg->RemoveHandler();
+      dlg->Close();
+      result = noErr;
+   }
+
+   return result;
+}
+
+
 void EventListener(void *inUserData, AudioUnitCarbonView inView, 
                    const AudioUnitParameter *inParameter,
                    AudioUnitCarbonViewEventID inEvent, 
@@ -747,7 +773,9 @@
                                  AudioUnitCarbonView carbonView,
                                  Effect *effect):
    mUnit(unit),
-   mEffect(effect)
+   mEffect(effect),
+   mHandlerUPP(NULL),
+   mHandlerRef(NULL)
 {
    long style = wxDEFAULT_DIALOG_STYLE;
    
@@ -860,20 +888,41 @@
    mMainSizer->Fit(this);
    mMainSizer->SetSizeHints(this);
 
-  #if ((wxMAJOR_VERSION == 2) && (wxMINOR_VERSION <= 4))
+   // Some VST effects do not work unless the default handler is removed since
+   // it captures many of the events that the plugins need.  But, it must be
+   // done last since proper window sizing will not occur otherwise.
+   ::RemoveEventHandler((EventHandlerRef)MacGetEventHandler());
 
-   // Nothing more to to...
+   // Install a bare minimum handler so we can capture the window close event. 
 If
+   // it's not captured, we will crash at Audacity termination since the window
+   // is still on the wxWidgets toplevel window lists, but it's already gone.
+   mHandlerUPP = NewEventHandlerUPP(EventHandler);
+   InstallWindowEventHandler(windowRef,
+                             mHandlerUPP,
+                             GetEventTypeCount(eventList),
+                             eventList,
+                             this,
+                             &mHandlerRef);
 
-  #else
+}
 
-   //
-   // Remove the wx event handler (because it interferes with the
-   // event handlers that other GUIs install)
-   //
+AudioUnitDialog::~AudioUnitDialog()
+{
+   RemoveHandler();
+}
 
-   ::RemoveEventHandler((EventHandlerRef)MacGetEventHandler());
+void AudioUnitDialog::RemoveHandler()
+{
+   if (mHandlerRef) {
+      ::RemoveEventHandler(mHandlerRef);
+      mHandlerRef = NULL;
+      MacInstallTopLevelWindowEventHandler();
+   }
 
-  #endif
+   if (mHandlerUPP) {
+      DisposeEventHandlerUPP(mHandlerUPP);
+      mHandlerUPP = NULL;
+   }
 }
 
 void AudioUnitDialog::OnOK(wxCommandEvent &event)


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to