@@ -64,7 +64,6 @@ class ConnectionMessageDisplay final
6464
6565 // So we can safely assign activeConnection
6666 activeConnection = connection;
67- hasConnection = connection != nullptr ;
6867
6968 if (connection) {
7069 connectionPtr = pd::WeakReference (connection->getPointer (), pd);
@@ -82,7 +81,9 @@ class ConnectionMessageDisplay final
8281 startTimer (RepaintTimer, 1000 / 60 );
8382 updateTextString (true );
8483 }
84+ hasConnection = true ;
8585 } else {
86+ hasConnection = false ;
8687 connectionPtr = pd::WeakReference (nullptr , pd);
8788 hideDisplay ();
8889 // to copy tooltip behaviour, any successful interaction will cause the next interaction to have no delay
@@ -95,18 +96,17 @@ class ConnectionMessageDisplay final
9596
9697 void updateSignalData ()
9798 {
98- if (hasConnection) {
99- if (auto oc = connectionPtr.get <t_outconnect>()) {
100- if (auto const * signal = outconnect_get_signal (oc.get ())) {
101- auto const numChannels = std::min (signal->s_nchans , 7 );
102- if (numChannels > 0 ) {
103- auto * samples = signal->s_vec ;
104- if (!samples) return ;
105-
106- float output[2048 ];
107- std::copy_n (samples, libpd_blocksize () * numChannels, output);
108- sampleQueue.try_enqueue (SignalBlock (output, numChannels));
109- }
99+ if (hasConnection && !connectionPtr.isDeleted ()) {
100+ auto * oc = connectionPtr.getRaw <t_outconnect>(); // No need to lock because this is called from the audio thread
101+ if (auto const * signal = outconnect_get_signal (oc)) {
102+ auto const numChannels = std::min (signal->s_nchans , 7 );
103+ if (numChannels > 0 ) {
104+ auto * samples = signal->s_vec ;
105+ if (!samples) return ;
106+
107+ float output[2048 ];
108+ std::copy_n (samples, libpd_blocksize () * numChannels, output);
109+ sampleQueue.try_enqueue (SignalBlock (output, numChannels));
110110 }
111111 }
112112 }
0 commit comments