From 82dd7545c9a5f26cb9fb93f87622c6183745dc94 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 14 Mar 2017 19:54:11 -0400 Subject: [PATCH] Reviewed uses of release(); prefer Destroy_ptr to hold window objects --- src/Menus.cpp | 6 ++++-- src/Project.cpp | 11 ++--------- src/Project.h | 4 ++-- src/TrackPanel.cpp | 2 +- src/effects/VST/VSTEffect.cpp | 2 +- src/effects/audiounits/AudioUnitEffect.cpp | 2 +- src/effects/lv2/LV2Effect.cpp | 4 +++- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 000ee7b49..185aa08f9 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -5609,7 +5609,8 @@ void AudacityProject::OnPlotSpectrum() where.x = 150; where.y = 150; - mFreqWindow = safenew FreqWindow(this, -1, _("Frequency Analysis"), where); + mFreqWindow.reset( safenew FreqWindow( + this, -1, _("Frequency Analysis"), where ) ); } mFreqWindow->Show(true); @@ -5626,7 +5627,8 @@ void AudacityProject::OnContrast() where.x = 150; where.y = 150; - mContrastDialog = safenew ContrastDialog(this, -1, _("Contrast Analysis (WCAG 2 compliance)"), where); + mContrastDialog.reset( safenew ContrastDialog( + this, -1, _("Contrast Analysis (WCAG 2 compliance)"), where ) ); } mContrastDialog->CentreOnParent(); diff --git a/src/Project.cpp b/src/Project.cpp index 276a5d5d8..346c39557 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -2482,15 +2482,8 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event) // Streams can be for play, recording, or monitoring. But maybe it still // makes sense to stop any recording before putting up the dialog. - if (mFreqWindow) { - mFreqWindow->Destroy(); - mFreqWindow = NULL; - } - - if (mContrastDialog) { - mContrastDialog->Destroy(); - mContrastDialog = NULL; - } + mFreqWindow.reset(); + mContrastDialog.reset(); // Check to see if we were playing or recording // audio, and if so, make sure Audio I/O is completely finished. diff --git a/src/Project.h b/src/Project.h index fc454ffc6..3888f742f 100644 --- a/src/Project.h +++ b/src/Project.h @@ -630,8 +630,8 @@ private: MixerBoard* mMixerBoard{}; MixerBoardFrame* mMixerBoardFrame{}; - FreqWindow *mFreqWindow{}; - ContrastDialog *mContrastDialog{}; + Destroy_ptr mFreqWindow; + Destroy_ptr mContrastDialog; // dialog for missing alias warnings wxDialog *mAliasMissingWarningDialog{}; diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index ec0bee7b8..ec0eded34 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -447,7 +447,7 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id, // wxWidgets owns the accessible object SetAccessible(mAx = pAx.release()); #else - // wxWidgets doesn not own the object, but we need to retain it + // wxWidgets does not own the object, but we need to retain it mAx = std::move(pAx); #endif } diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index e7201f188..636ba2d2e 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -2715,7 +2715,7 @@ void VSTEffect::BuildFancy() // Turn the power on...some effects need this when the editor is open PowerOn(); - auto control = std::make_unique(); + auto control = Destroy_ptr{ safenew VSTControl }; if (!control) { return; diff --git a/src/effects/audiounits/AudioUnitEffect.cpp b/src/effects/audiounits/AudioUnitEffect.cpp index b6b145d23..d9bd279e4 100644 --- a/src/effects/audiounits/AudioUnitEffect.cpp +++ b/src/effects/audiounits/AudioUnitEffect.cpp @@ -1729,7 +1729,7 @@ bool AudioUnitEffect::PopulateUI(wxWindow *parent) } else { - auto pControl = std::make_unique(); + auto pControl = Destroy_ptr( safenew AUControl ); if (!pControl) { return false; diff --git a/src/effects/lv2/LV2Effect.cpp b/src/effects/lv2/LV2Effect.cpp index cb1542461..86aad37c0 100644 --- a/src/effects/lv2/LV2Effect.cpp +++ b/src/effects/lv2/LV2Effect.cpp @@ -1398,7 +1398,9 @@ bool LV2Effect::BuildFancy() // Use a panel to host the plugins GUI // container is owned by mParent, but we may destroy it if there are // any errors before completing the build of UI. - auto container = std::make_unique(mParent, wxID_ANY); + auto container = Destroy_ptr{ + safenew wxPanelWrapper{ mParent, wxID_ANY} + }; if (!container) { lilv_uis_free(uis);