UI: Improve properties view object safety

Use weak references on OBS objects that properties view reference in
order to ensure that the objects are still valid.

This fixes a crash where properties views would use objects without
necessarily knowing whether they were still valid or not.

Fixes obsproject/obs-studio#5862
Closes obsproject/obs-studio#5863
This commit is contained in:
jp9000
2022-02-02 22:01:08 -08:00
parent edfd5ad604
commit f34b6866a5
2 changed files with 23 additions and 12 deletions

View File

@@ -97,7 +97,7 @@ private:
QWidget *widget = nullptr;
properties_t properties;
OBSData settings;
void *obj = nullptr;
OBSWeakObjectAutoRelease weakObj;
std::string type;
PropertiesReloadCallback reloadCallback;
PropertiesUpdateCallback callback = nullptr;
@@ -163,6 +163,11 @@ public:
inline obs_data_t *GetSettings() const { return settings; }
inline void UpdateSettings() { callback(obj, nullptr, settings); }
inline void UpdateSettings()
{
callback(OBSGetStrongRef(weakObj), nullptr, settings);
}
inline bool DeferUpdate() const { return deferUpdate; }
inline OBSObject GetObject() const { return OBSGetStrongRef(weakObj); }
};