mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-26 15:23:48 +01:00
Reviewed uses of release(); rewrote questionable ones in one file...
... Use of Destroy_ptr that was correct for 2.1.3 was no longer so after rewrites of Screenshot tool window management, which caused crashes that were worked-around with release(); but just use a bare pointer now.
This commit is contained in:
@@ -93,7 +93,11 @@ class ScreenFrame final : public wxFrame
|
|||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
using ScreenFramePtr = Destroy_ptr<ScreenFrame>;
|
// Static pointer to the unique ScreenFrame window.
|
||||||
|
// Formerly it was parentless, therefore this was a Destroy_ptr<ScreenFrame>
|
||||||
|
// But now the window is owned, so just use a bare pointer, and null it when
|
||||||
|
// the unique window is destroyed.
|
||||||
|
using ScreenFramePtr = ScreenFrame*;
|
||||||
ScreenFramePtr mFrame;
|
ScreenFramePtr mFrame;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -101,7 +105,12 @@ ScreenFramePtr mFrame;
|
|||||||
void OpenScreenshotTools()
|
void OpenScreenshotTools()
|
||||||
{
|
{
|
||||||
if (!mFrame) {
|
if (!mFrame) {
|
||||||
mFrame = ScreenFramePtr{ safenew ScreenFrame(wxGetApp().GetTopWindow(), -1) };
|
auto parent = wxGetApp().GetTopWindow();
|
||||||
|
if (!parent) {
|
||||||
|
wxASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mFrame = ScreenFramePtr{ safenew ScreenFrame(parent, -1) };
|
||||||
}
|
}
|
||||||
mFrame->Show();
|
mFrame->Show();
|
||||||
mFrame->Raise();
|
mFrame->Raise();
|
||||||
@@ -109,13 +118,7 @@ void OpenScreenshotTools()
|
|||||||
|
|
||||||
void CloseScreenshotTools()
|
void CloseScreenshotTools()
|
||||||
{
|
{
|
||||||
// The code below looks like a memory leak,
|
mFrame = nullptr;
|
||||||
// but actually wxWidgets will take care of deleting the
|
|
||||||
// screenshot window, becuase the parent window is
|
|
||||||
// being deleted. So we only need to free up our pointer
|
|
||||||
// to it, not actually delete the underlying object.
|
|
||||||
if( mFrame )
|
|
||||||
mFrame.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -281,8 +284,11 @@ ScreenFrame::ScreenFrame(wxWindow * parent, wxWindowID id)
|
|||||||
|
|
||||||
ScreenFrame::~ScreenFrame()
|
ScreenFrame::~ScreenFrame()
|
||||||
{
|
{
|
||||||
if( mFrame )
|
if (this == mFrame)
|
||||||
mFrame.release();
|
mFrame = nullptr;
|
||||||
|
else
|
||||||
|
// There should only be one!
|
||||||
|
wxASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenFrame::Populate()
|
void ScreenFrame::Populate()
|
||||||
@@ -486,8 +492,6 @@ bool ScreenFrame::ProcessEvent(wxEvent & e)
|
|||||||
|
|
||||||
void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
|
void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if (this == mFrame.get())
|
|
||||||
mFrame.release();
|
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user