From 1fad6292a245d8ddb57756ec88ce193eb2d4919b Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 16 Dec 2016 15:32:56 -0500 Subject: [PATCH] Exception safety in: overrides of ShowInterface --- src/effects/Effect.cpp | 14 ++++++-------- src/effects/Effect.h | 1 - src/effects/Equalization.cpp | 6 +----- src/effects/VST/VSTEffect.cpp | 8 ++++++-- src/effects/audiounits/AudioUnitEffect.cpp | 8 ++++++-- src/effects/ladspa/LadspaEffect.cpp | 8 ++++++-- src/effects/lv2/LV2Effect.cpp | 8 ++++++-- 7 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index c833fe66c..e0e36d7ed 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -88,8 +88,6 @@ WX_DECLARE_VOIDPTR_HASH_MAP( bool, t2bHash ); Effect::Effect() { - mParent = NULL; - mClient = NULL; mTracks = NULL; @@ -520,7 +518,8 @@ bool Effect::ShowInterface(wxWindow *parent, bool forceModal) if (mUIDialog) { - mUIDialog->Close(true); + if ( mUIDialog->Close(true) ) + mUIDialog = nullptr; return false; } @@ -529,8 +528,9 @@ bool Effect::ShowInterface(wxWindow *parent, bool forceModal) return mClient->ShowInterface(parent, forceModal); } - mParent = parent; - + // mUIDialog is null + auto cleanup = valueRestorer( mUIDialog ); + mUIDialog = CreateUI(parent, this); if (!mUIDialog) { @@ -544,14 +544,13 @@ bool Effect::ShowInterface(wxWindow *parent, bool forceModal) if (SupportsRealtime() && !forceModal) { mUIDialog->Show(); + cleanup.release(); // Return false to bypass effect processing return false; } bool res = mUIDialog->ShowModal() != 0; - mUIDialog = NULL; - mParent = NULL; return res; } @@ -1131,7 +1130,6 @@ bool Effect::DoEffect(wxWindow *parent, mFactory = factory; mProjectRate = projectRate; - mParent = parent; mTracks = list; bool isSelection = false; diff --git a/src/effects/Effect.h b/src/effects/Effect.h index 9010666fe..df57c9dcb 100644 --- a/src/effects/Effect.h +++ b/src/effects/Effect.h @@ -484,7 +484,6 @@ protected: // Used only by the base Effect class // private: - wxWindow *mParent; TrackList *mTracks; // the complete list of all tracks bool mIsBatch; diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index fa67ed2fb..41338f0fa 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -570,14 +570,10 @@ bool EffectEqualization::PopulateUI(wxWindow *parent) bool EffectEqualization::CloseUI() { - mUIParent->RemoveEventHandler(this); - - mUIParent = NULL; - mCurve = NULL; mPanel = NULL; - return true; + return Effect::CloseUI(); } void EffectEqualization::PopulateOrExchange(ShuttleGui & S) diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index 636ba2d2e..340afa4fc 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -1544,10 +1544,14 @@ bool VSTEffect::ShowInterface(wxWindow *parent, bool forceModal) { if (mDialog) { - mDialog->Close(true); + if ( mDialog->Close(true) ) + mDialog = nullptr; return false; } + // mDialog is null + auto cleanup = valueRestorer( mDialog ); + // mProcessLevel = 1; // in GUI thread // Set some defaults since some VSTs need them...these will be reset when @@ -1569,12 +1573,12 @@ bool VSTEffect::ShowInterface(wxWindow *parent, bool forceModal) if (SupportsRealtime() && !forceModal) { mDialog->Show(); + cleanup.release(); return false; } bool res = mDialog->ShowModal() != 0; - mDialog = NULL; return res; } diff --git a/src/effects/audiounits/AudioUnitEffect.cpp b/src/effects/audiounits/AudioUnitEffect.cpp index d9bd279e4..393885403 100644 --- a/src/effects/audiounits/AudioUnitEffect.cpp +++ b/src/effects/audiounits/AudioUnitEffect.cpp @@ -1423,10 +1423,14 @@ bool AudioUnitEffect::ShowInterface(wxWindow *parent, bool forceModal) { if (mDialog) { - mDialog->Close(true); + if( mDialog->Close(true) ) + mDialog = nullptr; return false; } + // mDialog is null + auto cleanup = valueRestorer( mDialog ); + mDialog = mHost->CreateUI(parent, this); if (!mDialog) { @@ -1436,12 +1440,12 @@ bool AudioUnitEffect::ShowInterface(wxWindow *parent, bool forceModal) if ((SupportsRealtime() || GetType() == EffectTypeAnalyze) && !forceModal) { mDialog->Show(); + cleanup.release(); return false; } bool res = mDialog->ShowModal() != 0; - mDialog = NULL; return res; } diff --git a/src/effects/ladspa/LadspaEffect.cpp b/src/effects/ladspa/LadspaEffect.cpp index fe77cc4d0..ae7d48b88 100644 --- a/src/effects/ladspa/LadspaEffect.cpp +++ b/src/effects/ladspa/LadspaEffect.cpp @@ -996,10 +996,14 @@ bool LadspaEffect::ShowInterface(wxWindow *parent, bool forceModal) { if (mDialog) { - mDialog->Close(true); + if ( mDialog->Close(true) ) + mDialog = nullptr; return false; } + // mDialog is null + auto cleanup = valueRestorer( mDialog ); + mDialog = mHost->CreateUI(parent, this); if (!mDialog) { @@ -1013,12 +1017,12 @@ bool LadspaEffect::ShowInterface(wxWindow *parent, bool forceModal) if ((SupportsRealtime() || GetType() == EffectTypeAnalyze) && !forceModal) { mDialog->Show(); + cleanup.release(); return false; } bool res = mDialog->ShowModal() != 0; - mDialog = NULL; return res; } diff --git a/src/effects/lv2/LV2Effect.cpp b/src/effects/lv2/LV2Effect.cpp index 86aad37c0..98a6a98ff 100644 --- a/src/effects/lv2/LV2Effect.cpp +++ b/src/effects/lv2/LV2Effect.cpp @@ -921,10 +921,14 @@ bool LV2Effect::ShowInterface(wxWindow *parent, bool forceModal) { if (mDialog) { - mDialog->Close(true); + if ( mDialog->Close(true) ) + mDialog = nullptr; return false; } + // mDialog is null + auto cleanup = valueRestorer( mDialog ); + mDialog = mHost->CreateUI(parent, this); if (!mDialog) { @@ -939,12 +943,12 @@ bool LV2Effect::ShowInterface(wxWindow *parent, bool forceModal) if ((SupportsRealtime() || GetType() == EffectTypeAnalyze) && !forceModal) { mDialog->Show(); + cleanup.release(); return false; } bool res = mDialog->ShowModal() != 0; - mDialog = NULL; return res; }