Fix overlay getting stuck if stopped to quickly after being started.

This commit is contained in:
Mr_Goldberg 2022-08-16 12:32:28 -04:00
parent bc4262a494
commit 077e532bd2
No known key found for this signature in database
GPG key ID: 8597D87419DEF278
3 changed files with 25 additions and 6 deletions

View file

@ -68,6 +68,15 @@ public:
return instance; return instance;
} }
static void deleteInst()
{
if (instance != nullptr)
{
delete instance;
instance = nullptr;
}
}
~Renderer_Detector() ~Renderer_Detector()
{ {
delete dx9_hook; delete dx9_hook;
@ -95,7 +104,8 @@ private:
dx12_hook(nullptr), dx12_hook(nullptr),
opengl_hook(nullptr), opengl_hook(nullptr),
vulkan_hook(nullptr), vulkan_hook(nullptr),
detection_done(false) detection_done(false),
force_done(false)
{ {
std::wstring tmp(4096, L'\0'); std::wstring tmp(4096, L'\0');
tmp.resize(GetSystemDirectoryW(&tmp[0], tmp.size())); tmp.resize(GetSystemDirectoryW(&tmp[0], tmp.size()));
@ -142,7 +152,7 @@ private:
OpenGL_Hook* opengl_hook; OpenGL_Hook* opengl_hook;
Vulkan_Hook* vulkan_hook; Vulkan_Hook* vulkan_hook;
bool detection_done; bool detection_done, force_done;
std::condition_variable stop_detection_cv; std::condition_variable stop_detection_cv;
std::mutex stop_detection_mutex; std::mutex stop_detection_mutex;
@ -1043,7 +1053,7 @@ public:
std::lock_guard<std::mutex> lk(renderer_mutex); std::lock_guard<std::mutex> lk(renderer_mutex);
if (detection_done) if (detection_done)
{ {
if (renderer_hook != nullptr) if (renderer_hook != nullptr || force_done)
return renderer_hook; return renderer_hook;
detection_done = false; detection_done = false;
@ -1122,6 +1132,7 @@ public:
{ {
System::scoped_lock lk(renderer_mutex, stop_detection_mutex); System::scoped_lock lk(renderer_mutex, stop_detection_mutex);
detection_done = true; detection_done = true;
force_done = true;
} }
stop_detection_cv.notify_all(); stop_detection_cv.notify_all();
} }
@ -1253,7 +1264,7 @@ public:
std::lock_guard<std::mutex> lk(renderer_mutex); std::lock_guard<std::mutex> lk(renderer_mutex);
if (detection_done) if (detection_done)
{ {
if (renderer_hook != nullptr) if (renderer_hook != nullptr || force_done)
return renderer_hook; return renderer_hook;
detection_done = false; detection_done = false;
@ -1305,6 +1316,7 @@ public:
{ {
System::scoped_lock lk(renderer_mutex, stop_detection_mutex); System::scoped_lock lk(renderer_mutex, stop_detection_mutex);
detection_done = true; detection_done = true;
force_done = true;
} }
stop_detection_cv.notify_all(); stop_detection_cv.notify_all();
} }
@ -1432,7 +1444,7 @@ public:
std::lock_guard<std::mutex> lk(renderer_mutex); std::lock_guard<std::mutex> lk(renderer_mutex);
if (detection_done) if (detection_done)
{ {
if (renderer_hook != nullptr) if (renderer_hook != nullptr || force_done)
return renderer_hook; return renderer_hook;
detection_done = false; detection_done = false;
@ -1484,6 +1496,7 @@ public:
{ {
System::scoped_lock lk(renderer_mutex, stop_detection_mutex); System::scoped_lock lk(renderer_mutex, stop_detection_mutex);
detection_done = true; detection_done = true;
force_done = true;
} }
stop_detection_cv.notify_all(); stop_detection_cv.notify_all();
} }
@ -1505,4 +1518,9 @@ void StopRendererDetection()
Renderer_Detector::Inst()->stop_detection(); Renderer_Detector::Inst()->stop_detection();
} }
void FreeRendererDetection()
{
Renderer_Detector::deleteInst();
}
} }

View file

@ -31,5 +31,5 @@ namespace ingame_overlay {
std::future<Renderer_Hook*> DetectRenderer(std::chrono::milliseconds timeout = std::chrono::milliseconds{ -1 }); std::future<Renderer_Hook*> DetectRenderer(std::chrono::milliseconds timeout = std::chrono::milliseconds{ -1 });
void StopRendererDetection(); void StopRendererDetection();
void FreeRendererDetection();
} }

View file

@ -207,6 +207,7 @@ void Steam_Overlay::UnSetupOverlay()
if (!Ready() && future_renderer.valid()) { if (!Ready() && future_renderer.valid()) {
if (future_renderer.wait_for(std::chrono::milliseconds{500}) == std::future_status::ready) { if (future_renderer.wait_for(std::chrono::milliseconds{500}) == std::future_status::ready) {
future_renderer.get(); future_renderer.get();
ingame_overlay::FreeRendererDetection();
} }
} }
} }