1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-26 00:58:37 +02:00

Fix dangling pointers to Project from LyricsWindow.cpp

This commit is contained in:
Paul Licameli 2021-07-15 11:11:19 -04:00 committed by Paul Licameli
parent 13cb2c2a3f
commit 0ee9cbd83e
2 changed files with 22 additions and 17 deletions

View File

@ -64,7 +64,8 @@ LyricsWindow::LyricsWindow(AudacityProject *parent)
// // WXMAC doesn't support wxFRAME_FLOAT_ON_PARENT, so we do // // WXMAC doesn't support wxFRAME_FLOAT_ON_PARENT, so we do
// SetWindowClass((WindowRef) MacGetWindowRef(), kFloatingWindowClass); // SetWindowClass((WindowRef) MacGetWindowRef(), kFloatingWindowClass);
// #endif // #endif
mProject = parent; auto pProject = parent->shared_from_this();
mProject = pProject;
SetWindowTitle(); SetWindowTitle();
auto titleChanged = [&](wxCommandEvent &evt) auto titleChanged = [&](wxCommandEvent &evt)
@ -136,7 +137,7 @@ LyricsWindow::LyricsWindow(AudacityProject *parent)
//} //}
// Events from the project don't propagate directly to this other frame, so... // Events from the project don't propagate directly to this other frame, so...
mProject->Bind(EVT_TRACK_PANEL_TIMER, pProject->Bind(EVT_TRACK_PANEL_TIMER,
&LyricsWindow::OnTimer, &LyricsWindow::OnTimer,
this); this);
Center(); Center();
@ -159,7 +160,8 @@ void LyricsWindow::OnStyle_Highlight(wxCommandEvent & WXUNUSED(event))
void LyricsWindow::OnTimer(wxCommandEvent &event) void LyricsWindow::OnTimer(wxCommandEvent &event)
{ {
if (ProjectAudioIO::Get( *mProject ).IsAudioActive()) if (auto pProject = mProject.lock()) {
if (ProjectAudioIO::Get( *pProject ).IsAudioActive())
{ {
auto gAudioIO = AudioIO::Get(); auto gAudioIO = AudioIO::Get();
GetLyricsPanel()->Update(gAudioIO->GetStreamTime()); GetLyricsPanel()->Update(gAudioIO->GetStreamTime());
@ -167,9 +169,10 @@ void LyricsWindow::OnTimer(wxCommandEvent &event)
else else
{ {
// Reset lyrics display. // Reset lyrics display.
const auto &selectedRegion = ViewInfo::Get( *mProject ).selectedRegion; const auto &selectedRegion = ViewInfo::Get( *pProject ).selectedRegion;
GetLyricsPanel()->Update(selectedRegion.t0()); GetLyricsPanel()->Update(selectedRegion.t0());
} }
}
// Let other listeners get the notification // Let other listeners get the notification
event.Skip(); event.Skip();
@ -177,9 +180,10 @@ void LyricsWindow::OnTimer(wxCommandEvent &event)
void LyricsWindow::SetWindowTitle() void LyricsWindow::SetWindowTitle()
{ {
wxString name = mProject->GetProjectName(); wxString name;
if (auto pProject = mProject.lock()) {
name = pProject->GetProjectName();
if (!name.empty()) if (!name.empty())
{
name.Prepend(wxT(" - ")); name.Prepend(wxT(" - "));
} }

View File

@ -13,6 +13,7 @@
#define __AUDACITY_LYRICS_WINDOW__ #define __AUDACITY_LYRICS_WINDOW__
#include <wx/frame.h> // to inherit #include <wx/frame.h> // to inherit
#include <memory>
#include "Prefs.h" #include "Prefs.h"
@ -40,7 +41,7 @@ class LyricsWindow final : public wxFrame,
// PrefsListener implementation // PrefsListener implementation
void UpdatePrefs() override; void UpdatePrefs() override;
AudacityProject *mProject; std::weak_ptr<AudacityProject> mProject;
LyricsPanel *mLyricsPanel; LyricsPanel *mLyricsPanel;
public: public: