1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 17:10:55 +02:00

Some uses of Destroy_ptr let us remove some naked news

This commit is contained in:
Paul Licameli 2016-08-09 22:46:59 -04:00
parent aaeaadff07
commit fec4069d9d
5 changed files with 36 additions and 37 deletions

View File

@ -1766,8 +1766,11 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
wxUNIXaddress addr; wxUNIXaddress addr;
addr.Filename(sockFile); addr.Filename(sockFile);
{
// Setup the socket // Setup the socket
wxSocketClient *sock = new wxSocketClient(); // A wxSocketClient must not be deleted by us, but rather, let the
// framework do appropriate delayed deletion after Destroy()
Destroy_ptr<wxSocketClient> sock { safenew wxSocketClient() };
sock->SetFlags(wxSOCKET_WAITALL); sock->SetFlags(wxSOCKET_WAITALL);
// We try up to 50 times since there's a small window // We try up to 50 times since there's a small window
@ -1785,14 +1788,12 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar)); sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar));
} }
sock->Destroy();
return false; return false;
} }
wxMilliSleep(100); wxMilliSleep(100);
} }
}
sock->Destroy();
#endif #endif
// There is another copy of Audacity running. Force quit. // There is another copy of Audacity running. Force quit.

View File

@ -111,14 +111,15 @@ class ScreenFrame final : public wxFrame
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
static ScreenFrame *mFrame = NULL; using ScreenFramePtr = Destroy_ptr<ScreenFrame>;
ScreenFramePtr mFrame;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void OpenScreenshotTools() void OpenScreenshotTools()
{ {
if (!mFrame) { if (!mFrame) {
mFrame = new ScreenFrame(NULL, -1); mFrame = ScreenFramePtr{ safenew ScreenFrame(NULL, -1) };
} }
mFrame->Show(); mFrame->Show();
mFrame->Raise(); mFrame->Raise();
@ -126,10 +127,7 @@ void OpenScreenshotTools()
void CloseScreenshotTools() void CloseScreenshotTools()
{ {
if (mFrame) { mFrame.reset();
mFrame->Destroy();
mFrame = NULL;
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -485,7 +483,8 @@ bool ScreenFrame::ProcessEvent(wxEvent & e)
void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event)) void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
{ {
mFrame = NULL; if (this == mFrame.get())
mFrame.release();
Destroy(); Destroy();
} }

View File

@ -779,15 +779,15 @@ void Effect::Preview()
wxDialog *Effect::CreateUI(wxWindow *parent, EffectUIClientInterface *client) wxDialog *Effect::CreateUI(wxWindow *parent, EffectUIClientInterface *client)
{ {
EffectUIHost *dlg = new EffectUIHost(parent, this, client); Destroy_ptr<EffectUIHost> dlg
{ safenew EffectUIHost{ parent, this, client} };
if (dlg->Initialize()) if (dlg->Initialize())
{ {
return dlg; // release() is safe because parent will own it
return dlg.release();
} }
delete dlg;
return NULL; return NULL;
} }

View File

@ -363,7 +363,7 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
mLeft = std::make_unique<wxRegion>( 3, &pt[0] ); mLeft = std::make_unique<wxRegion>( 3, &pt[0] );
// Create the indicator frame // Create the indicator frame
mIndicator = new wxFrame( NULL, mIndicator = FramePtr{ safenew wxFrame( NULL,
wxID_ANY, wxID_ANY,
wxEmptyString, wxEmptyString,
wxDefaultPosition, wxDefaultPosition,
@ -372,7 +372,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
wxFRAME_SHAPED | wxFRAME_SHAPED |
wxNO_BORDER | wxNO_BORDER |
wxFRAME_NO_TASKBAR | wxFRAME_NO_TASKBAR |
wxSTAY_ON_TOP ); wxSTAY_ON_TOP )
};
// Hook the creation event...only needed on GTK, but doesn't hurt for all // Hook the creation event...only needed on GTK, but doesn't hurt for all
mIndicator->Connect( wxEVT_CREATE, mIndicator->Connect( wxEVT_CREATE,
@ -462,9 +463,6 @@ ToolManager::~ToolManager()
wxPaintEventHandler( ToolManager::OnIndicatorPaint ), wxPaintEventHandler( ToolManager::OnIndicatorPaint ),
NULL, NULL,
this ); this );
// Must destroy the window since it doesn't have a parent
mIndicator->Destroy();
} }
// This table describes the default configuration of the toolbars as // This table describes the default configuration of the toolbars as

View File

@ -97,7 +97,8 @@ class ToolManager final : public wxEvtHandler
wxPoint mLastPos; wxPoint mLastPos;
wxRect mBarPos; wxRect mBarPos;
wxFrame *mIndicator; using FramePtr = Destroy_ptr<wxFrame>;
FramePtr mIndicator;
std::unique_ptr<wxRegion> mLeft, mDown; std::unique_ptr<wxRegion> mLeft, mDown;
wxRegion *mCurrent; wxRegion *mCurrent;