Skip to content

Commit dd84582

Browse files
Copilotumireon
andauthored
Fix race conditions in enhance-filter model updates and update-checker version string (#719)
* Initial plan * Fix race conditions in enhance-filter and update-checker Co-authored-by: umireon <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: umireon <[email protected]>
1 parent b3d01d4 commit dd84582

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/enhance-filter.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct enhance_filter : public filter_data {
2929
cv::Mat outputBGRA;
3030
gs_effect_t *blendEffect;
3131
float blendFactor;
32+
33+
std::mutex modelMutex;
3234
};
3335

3436
const char *enhance_filter_getname(void *unused)
@@ -116,6 +118,9 @@ void enhance_filter_update(void *data, obs_data_t *settings)
116118

117119
if (tf->modelSelection.empty() || tf->modelSelection != newModel || tf->useGPU != newUseGpu ||
118120
tf->numThreads != newNumThreads) {
121+
// Lock modelMutex to prevent race condition with video_tick
122+
std::unique_lock<std::mutex> lock(tf->modelMutex);
123+
119124
tf->numThreads = newNumThreads;
120125
tf->modelSelection = newModel;
121126
if (tf->modelSelection == MODEL_ENHANCE_TBEFN) {
@@ -203,13 +208,16 @@ void enhance_filter_video_tick(void *data, float seconds)
203208
}
204209

205210
cv::Mat outputImage;
206-
try {
207-
if (!runFilterModelInference(tf, imageBGRA, outputImage)) {
211+
{
212+
std::unique_lock<std::mutex> lock(tf->modelMutex);
213+
try {
214+
if (!runFilterModelInference(tf, imageBGRA, outputImage)) {
215+
return;
216+
}
217+
} catch (const std::exception &e) {
218+
obs_log(LOG_ERROR, "Exception caught: %s", e.what());
208219
return;
209220
}
210-
} catch (const std::exception &e) {
211-
obs_log(LOG_ERROR, "Exception caught: %s", e.what());
212-
return;
213221
}
214222

215223
// Put output image back to source rendering pipeline

src/update-checker/update-checker.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
#include <plugin-support.h>
99

10+
#include <mutex>
11+
1012
extern "C" const char *PLUGIN_VERSION;
1113

1214
static std::string latestVersionForUpdate;
15+
static std::mutex latestVersionMutex;
1316

1417
void check_update(void)
1518
{
@@ -35,10 +38,12 @@ void check_update(void)
3538

3639
if (info.version == PLUGIN_VERSION) {
3740
// No update available, latest version is the same as the current version
41+
std::lock_guard<std::mutex> lock(latestVersionMutex);
3842
latestVersionForUpdate.clear();
3943
return;
4044
}
4145

46+
std::lock_guard<std::mutex> lock(latestVersionMutex);
4247
latestVersionForUpdate = info.version;
4348
};
4449

@@ -47,6 +52,7 @@ void check_update(void)
4752

4853
const char *get_latest_version(void)
4954
{
55+
std::lock_guard<std::mutex> lock(latestVersionMutex);
5056
obs_log(LOG_INFO, "get_latest_version: %s", latestVersionForUpdate.c_str());
5157
if (latestVersionForUpdate.empty()) {
5258
return nullptr;

0 commit comments

Comments
 (0)