diff audio/AudioCallbackRecordTarget.cpp @ 641:dfec6c96007d

Wire up modelAboutToBeDeleted which appears to have been missed earlier - fixing crash when timer fires after model deleted e.g. on app exit
author Chris Cannam
date Fri, 04 Jan 2019 15:23:53 +0000
parents 5e0018969003
children 92ad94dee103
line wrap: on
line diff
--- a/audio/AudioCallbackRecordTarget.cpp	Wed Dec 19 09:31:47 2018 +0000
+++ b/audio/AudioCallbackRecordTarget.cpp	Fri Jan 04 15:23:53 2019 +0000
@@ -16,6 +16,7 @@
 
 #include "base/ViewManagerBase.h"
 #include "base/RecordDirectory.h"
+#include "base/Debug.h"
 
 #include "data/model/WritableWaveFileModel.h"
 
@@ -51,6 +52,10 @@
 
 AudioCallbackRecordTarget::~AudioCallbackRecordTarget()
 {
+#ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET
+    cerr << "AudioCallbackRecordTarget dtor" << endl;
+#endif
+    
     m_viewManager->setAudioRecordTarget(0);
 
     QMutexLocker locker(&m_bufPtrMutex);
@@ -169,6 +174,13 @@
     cerr << "AudioCallbackRecordTarget::updateModel: have " << nframes << " frames" << endl;
 #endif
 
+    if (!m_model) {
+#ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET
+        cerr << "AudioCallbackRecordTarget::updateModel: have no model to update; I am hoping there is a good reason for this" << endl;
+#endif
+        return;
+    }
+
     float **samples = new float *[m_recordChannelCount];
     for (int c = 0; c < m_recordChannelCount; ++c) {
         samples[c] = new float[nframes];
@@ -217,8 +229,13 @@
 AudioCallbackRecordTarget::modelAboutToBeDeleted()
 {
     if (sender() == m_model) {
+#ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET
+        cerr << "AudioCallbackRecordTarget::modelAboutToBeDeleted: taking note" << endl;
+#endif
         m_model = 0;
         m_recording = false;
+    } else {
+        SVCERR << "WARNING: AudioCallbackRecordTarget::modelAboutToBeDeleted: ths is not my model!" << endl;
     }
 }
 
@@ -263,6 +280,9 @@
         return 0;
     }
 
+    connect(m_model, SIGNAL(aboutToBeDeleted()), 
+            this, SLOT(modelAboutToBeDeleted()));
+
     m_model->setObjectName(label);
     m_recording = true;