mirror of
				https://github.com/cookiengineer/audacity
				synced 2025-10-31 06:03:49 +01:00 
			
		
		
		
	Fix dangling pointers to Project from LyricsWindow.cpp
(cherry picked from audacity commit 0ee9cbd83e)
Signed-off-by: akleja <storspov@gmail.com>
			
			
This commit is contained in:
		| @@ -63,7 +63,8 @@ LyricsWindow::LyricsWindow(AudacityProject *parent) | ||||
|    //      // WXMAC doesn't support wxFRAME_FLOAT_ON_PARENT, so we do
 | ||||
|    //      SetWindowClass((WindowRef) MacGetWindowRef(), kFloatingWindowClass);
 | ||||
|    //   #endif
 | ||||
|    mProject = parent; | ||||
|    auto pProject = parent->shared_from_this(); | ||||
|    mProject = pProject; | ||||
| 
 | ||||
|    SetWindowTitle(); | ||||
|    auto titleChanged = [&](wxCommandEvent &evt) | ||||
| @@ -135,7 +136,7 @@ LyricsWindow::LyricsWindow(AudacityProject *parent) | ||||
|    //}
 | ||||
| 
 | ||||
|    // 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, | ||||
|       this); | ||||
|    Center(); | ||||
| @@ -158,16 +159,18 @@ void LyricsWindow::OnStyle_Highlight(wxCommandEvent & WXUNUSED(event)) | ||||
| 
 | ||||
| void LyricsWindow::OnTimer(wxCommandEvent &event) | ||||
| { | ||||
|    if (ProjectAudioIO::Get( *mProject ).IsAudioActive()) | ||||
|    { | ||||
|       auto gAudioIO = AudioIO::Get(); | ||||
|       GetLyricsPanel()->Update(gAudioIO->GetStreamTime()); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       // Reset lyrics display.
 | ||||
|       const auto &selectedRegion = ViewInfo::Get( *mProject ).selectedRegion; | ||||
|       GetLyricsPanel()->Update(selectedRegion.t0()); | ||||
|    if (auto pProject = mProject.lock()) { | ||||
|       if (ProjectAudioIO::Get( *pProject ).IsAudioActive()) | ||||
|       { | ||||
|          auto gAudioIO = AudioIO::Get(); | ||||
|          GetLyricsPanel()->Update(gAudioIO->GetStreamTime()); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          // Reset lyrics display.
 | ||||
|          const auto &selectedRegion = ViewInfo::Get( *pProject ).selectedRegion; | ||||
|          GetLyricsPanel()->Update(selectedRegion.t0()); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    // Let other listeners get the notification
 | ||||
| @@ -176,10 +179,11 @@ void LyricsWindow::OnTimer(wxCommandEvent &event) | ||||
| 
 | ||||
| void LyricsWindow::SetWindowTitle() | ||||
| { | ||||
|    wxString name = mProject->GetProjectName(); | ||||
|    if (!name.empty()) | ||||
|    { | ||||
|       name.Prepend(wxT(" - ")); | ||||
|    wxString name; | ||||
|    if (auto pProject = mProject.lock()) { | ||||
|       name = pProject->GetProjectName(); | ||||
|       if (!name.empty()) | ||||
|          name.Prepend(wxT(" - ")); | ||||
|    } | ||||
| 
 | ||||
|    SetTitle(AudacityKaraokeTitle.Format(name).Translation()); | ||||
|   | ||||
| @@ -13,6 +13,7 @@ | ||||
| #define __AUDACITY_LYRICS_WINDOW__ | ||||
| 
 | ||||
| #include <wx/frame.h> // to inherit | ||||
| #include <memory> | ||||
| 
 | ||||
| #include "Prefs.h" | ||||
| 
 | ||||
| @@ -40,7 +41,7 @@ class LyricsWindow final : public wxFrame, | ||||
|    // PrefsListener implementation
 | ||||
|    void UpdatePrefs() override; | ||||
| 
 | ||||
|    AudacityProject *mProject; | ||||
|    std::weak_ptr<AudacityProject> mProject; | ||||
|    LyricsPanel *mLyricsPanel; | ||||
| 
 | ||||
|  public: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user