File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -144,12 +144,30 @@ auto as_const_ptr(T *ptr) noexcept -> std::add_const_t<T>* { return ptr; }
144144
145145struct SpaHook : spa_hook {
146146 SpaHook () : spa_hook{} { }
147- ~SpaHook () { spa_hook_remove (this ); }
147+ ~SpaHook ()
148+ {
149+ /* Prior to 0.3.57, spa_hook_remove will crash if the spa_hook hasn't
150+ * been linked with anything, which complicates removing on destruction
151+ * since the spa_hook object needs to exist before it's linked, but if
152+ * linking fails, there's no function to test if it can be removed. The
153+ * PipeWire headers say spa_hook should be treated as opaque, meaning
154+ * accessing any fields directly risks breaking compilation in the
155+ * future. So we only peek into the spa_hool to do this check on older
156+ * versions that need it.
157+ */
158+ #if !PW_CHECK_VERSION(0,3,57)
159+ if (this ->link .prev != nullptr )
160+ #endif
161+ spa_hook_remove (this );
162+ }
148163
149164 void remove ()
150165 {
151- spa_hook_remove (this );
152- static_cast <spa_hook&>(*this ) = {};
166+ #if !PW_CHECK_VERSION(0,3,57)
167+ if (this ->link .prev != nullptr )
168+ #endif
169+ spa_hook_remove (this );
170+ static_cast <spa_hook&>(*this ) = spa_hook{};
153171 }
154172
155173 SpaHook (const SpaHook&) = delete ;
You can’t perform that action at this time.
0 commit comments