From a0f5cb56a25127c4314e94ef018e4f4156755156 Mon Sep 17 00:00:00 2001 From: jackun Date: Mon, 16 Mar 2020 18:52:03 +0200 Subject: [PATCH] [config] Guard overlay_params from the thread with mutex --- src/notify.cpp | 4 +++- src/notify.h | 2 ++ src/overlay.cpp | 8 +++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/notify.cpp b/src/notify.cpp index 9ca35941..866daff3 100644 --- a/src/notify.cpp +++ b/src/notify.cpp @@ -23,8 +23,10 @@ void *fileChanged(void *params_void){ struct inotify_event *event = (struct inotify_event *) &buffer[i]; i += EVENT_SIZE + event->len; - if (event->mask & IN_MODIFY) + if (event->mask & IN_MODIFY) { + std::lock_guard lk(nt->mutex); parse_overlay_config(nt->params, getenv("MANGOHUD_CONFIG")); + } } i = 0; printf("File Changed\n"); diff --git a/src/notify.h b/src/notify.h index 3a735936..ee09e74c 100644 --- a/src/notify.h +++ b/src/notify.h @@ -1,10 +1,12 @@ #include +#include #include "overlay_params.h" struct notify_thread { overlay_params *params = nullptr; bool quit = false; + std::mutex mutex; }; extern pthread_t fileChange; diff --git a/src/overlay.cpp b/src/overlay.cpp index 8045bbe3..6576d25e 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -1296,9 +1296,11 @@ static void compute_swapchain_display(struct swapchain_data *data) ImGui::SetCurrentContext(data->imgui_context); ImGui::NewFrame(); - - position_layer(instance_data->params, data->window_size, data->width, data->height); - render_imgui(data->sw_stats, instance_data->params, data->window_size, data->width, data->height, true); + { + scoped_lock lk(instance_data->notifier.mutex); + position_layer(instance_data->params, data->window_size, data->width, data->height); + render_imgui(data->sw_stats, instance_data->params, data->window_size, data->width, data->height, true); + } ImGui::PopStyleVar(3); ImGui::EndFrame();