Skip to content

Commit dded0ac

Browse files
committed
fix connectionlistener bugs
1 parent 952ebac commit dded0ac

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

Source/Components/ConnectionMessageDisplay.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Source/Objects/ScalarObject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,6 @@ class DrawablePlot final : public DrawableTemplate
912912
if(!s->sc_template)
913913
return;
914914

915-
auto const* glist = canvas->patch.getPointer().get();
916-
917915
auto* x = reinterpret_cast<t_fake_plot*>(object);
918916
int elemsize, yonset, wonset, xonset, i;
919917
t_canvas* elemtemplatecanvas;

Source/Pd/WeakReference.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ struct WeakReference {
104104
{
105105
return weakRef && ptr != nullptr;
106106
}
107+
108+
bool isDeleted() const noexcept
109+
{
110+
return !weakRef;
111+
}
107112

108113
private:
109114
void* ptr;

0 commit comments

Comments
 (0)