Fix overlay crash in games that load then unload steam api dll.

merge-requests/50/head
Mr_Goldberg 2022-08-07 23:11:21 -04:00
parent e0726f2e9d
commit 7c419e0afe
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
5 changed files with 40 additions and 2 deletions

View File

@ -830,6 +830,11 @@ bool Steam_Client::BShutdownIfAllPipesClosed()
}
steam_controller->Shutdown();
#ifdef EMU_OVERLAY
if(!settings_client->disable_overlay)
steam_overlay->UnSetupOverlay();
#endif
if (joinable) {
background_keepalive.join();
}

View File

@ -77,6 +77,10 @@ public:
delete vulkan_hook;
}
bool force_stop_detection;
std::condition_variable detect_renderer_thread_cv;
std::mutex destroy_render_thread_mutex;
private:
Renderer_Detector():
dxgi_hooked(false),
@ -94,7 +98,8 @@ private:
dx12_hook(nullptr),
opengl_hook(nullptr),
vulkan_hook(nullptr),
detection_done(false)
detection_done(false),
force_stop_detection(false)
{
std::wstring tmp(4096, L'\0');
tmp.resize(GetSystemDirectoryW(&tmp[0], tmp.size()));
@ -1064,6 +1069,9 @@ public:
auto start_time = std::chrono::steady_clock::now();
do
{
std::unique_lock<std::mutex> lck(destroy_render_thread_mutex);
if (force_stop_detection) break;
for (auto const& library : libraries)
{
void* lib_handle = System::Library::GetLibraryHandle(library.first.c_str());
@ -1074,7 +1082,10 @@ public:
(this->*library.second)(name);
}
}
std::this_thread::sleep_for(std::chrono::milliseconds{ 100 });
detect_renderer_thread_cv.wait_for(lck, std::chrono::milliseconds(100));
if (force_stop_detection) break;
} while (!detection_done && (timeout.count() == -1 || (std::chrono::steady_clock::now() - start_time) <= timeout));
{
@ -1415,3 +1426,11 @@ std::future<Renderer_Hook*> detect_renderer(std::chrono::milliseconds timeout)
{
return std::async(std::launch::async, &Renderer_Detector::detect_renderer, Renderer_Detector::Inst(), timeout);
}
void stop_renderer_detector()
{
Renderer_Detector::Inst()->destroy_render_thread_mutex.lock();
Renderer_Detector::Inst()->force_stop_detection = true;
Renderer_Detector::Inst()->destroy_render_thread_mutex.unlock();
Renderer_Detector::Inst()->detect_renderer_thread_cv.notify_all();
}

View File

@ -28,3 +28,4 @@
#include "Renderer_Hook.h"
std::future<Renderer_Hook*> detect_renderer(std::chrono::milliseconds timeout = std::chrono::milliseconds{-1});
void stop_renderer_detector();

View File

@ -200,6 +200,17 @@ void Steam_Overlay::SetupOverlay()
}
}
void Steam_Overlay::UnSetupOverlay()
{
stop_renderer_detector();
if (!Ready() && future_renderer.valid()) {
if (future_renderer.wait_for(std::chrono::milliseconds{500}) == std::future_status::ready) {
future_renderer.get();
}
}
}
void Steam_Overlay::HookReady(bool ready)
{
{

View File

@ -161,6 +161,7 @@ public:
void SetNotificationInset(int nHorizontalInset, int nVerticalInset);
void SetupOverlay();
void UnSetupOverlay();
void HookReady(bool ready);
@ -202,6 +203,7 @@ public:
void SetNotificationInset(int nHorizontalInset, int nVerticalInset) {}
void SetupOverlay() {}
void UnSetupOverlay() {}
void HookReady(bool ready) {}