mirror of
https://github.com/flightlessmango/MangoHud.git
synced 2024-10-31 15:20:13 +00:00
config: add a mutex for config
We want to wait to render before config has been fully loaded. Otherwise this can sometimes cause a crash when we access config options while they are being assigned.
This commit is contained in:
parent
4aa92187a7
commit
33b8924384
@ -666,6 +666,8 @@ void horizontal_separator(struct overlay_params& params) {
|
|||||||
|
|
||||||
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan)
|
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(config_mtx);
|
||||||
|
config_cv.wait(lock, []{ return config_ready; });
|
||||||
// data.engine = EngineTypes::GAMESCOPE;
|
// data.engine = EngineTypes::GAMESCOPE;
|
||||||
HUDElements.sw_stats = &data; HUDElements.params = ¶ms;
|
HUDElements.sw_stats = &data; HUDElements.params = ¶ms;
|
||||||
HUDElements.is_vulkan = is_vulkan;
|
HUDElements.is_vulkan = is_vulkan;
|
||||||
|
@ -41,6 +41,9 @@
|
|||||||
#include "fps_metrics.h"
|
#include "fps_metrics.h"
|
||||||
|
|
||||||
std::unique_ptr<fpsMetrics> fpsmetrics;
|
std::unique_ptr<fpsMetrics> fpsmetrics;
|
||||||
|
std::mutex config_mtx;
|
||||||
|
std::condition_variable config_cv;
|
||||||
|
bool config_ready = false;
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
|
|
||||||
@ -1001,6 +1004,12 @@ parse_overlay_config(struct overlay_params *params,
|
|||||||
#endif
|
#endif
|
||||||
if (HUDElements.net)
|
if (HUDElements.net)
|
||||||
HUDElements.net->should_reset = true;
|
HUDElements.net->should_reset = true;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(config_mtx);
|
||||||
|
config_ready = true;
|
||||||
|
config_cv.notify_one();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse_preset_config(int preset, struct overlay_params *params){
|
bool parse_preset_config(int preset, struct overlay_params *params){
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -330,9 +332,11 @@ void parse_overlay_config(struct overlay_params *params,
|
|||||||
void presets(int preset, struct overlay_params *params, bool inherit=false);
|
void presets(int preset, struct overlay_params *params, bool inherit=false);
|
||||||
bool parse_preset_config(int preset, struct overlay_params *params);
|
bool parse_preset_config(int preset, struct overlay_params *params);
|
||||||
void add_to_options(struct overlay_params *params, std::string option, std::string value);
|
void add_to_options(struct overlay_params *params, std::string option, std::string value);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
extern std::mutex config_mtx;
|
||||||
|
extern std::condition_variable config_cv;
|
||||||
|
extern bool config_ready;
|
||||||
|
|
||||||
#endif /* MANGOHUD_OVERLAY_PARAMS_H */
|
#endif /* MANGOHUD_OVERLAY_PARAMS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user