Skip to content

Commit e50e534

Browse files
committed
services/pipewire: destroy qml ifaces early to avoid user callbacks
Consumers of defaultAudio*Changed signals can run code between safeDestroy being called and PwObjectIface destruction due to signal connection order. This change destroys ifaces earlier so they are nulled by the time a changed signal is fired from destruction. Fixes #116 #122 #124
1 parent 201c559 commit e50e534

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/services/pipewire/qml.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818

1919
namespace qs::service::pipewire {
2020

21+
PwObjectIface::PwObjectIface(PwBindableObject* object): QObject(object), object(object) {
22+
// We want to destroy the interface before QObject::destroyed is fired, as handlers
23+
// connected before PwObjectIface will run first and emit signals that hit user code,
24+
// which can then try to reference the iface again.
25+
QObject::connect(object, &PwBindableObject::destroying, this, &PwObjectIface::onObjectDestroying);
26+
}
27+
28+
void PwObjectIface::onObjectDestroying() { delete this; }
29+
2130
void PwObjectIface::ref() {
2231
this->refcount++;
2332

src/services/pipewire/qml.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ class PwObjectIface
3636
Q_OBJECT;
3737

3838
public:
39-
explicit PwObjectIface(PwBindableObject* object): QObject(object), object(object) {};
39+
explicit PwObjectIface(PwBindableObject* object);
4040
// destructor should ONLY be called by the pw object destructor, making an unref unnecessary
4141
~PwObjectIface() override = default;
4242
Q_DISABLE_COPY_MOVE(PwObjectIface);
4343

4444
void ref() override;
4545
void unref() override;
4646

47+
private slots:
48+
void onObjectDestroying();
49+
4750
private:
4851
quint32 refcount = 0;
4952
PwBindableObject* object;

0 commit comments

Comments
 (0)