win32: Try to handle race in changing drivers.

This commit is contained in:
BearOso 2023-02-20 15:15:38 -06:00
parent 4f08da4cd8
commit 54770ef3cc
2 changed files with 25 additions and 7 deletions

View File

@ -14,9 +14,15 @@ bool CVulkan::Initialize(HWND hWnd)
current_width = window_rect.right - window_rect.left;
current_height = window_rect.bottom - window_rect.top;
context = std::make_unique<Vulkan::Context>();
if (!context->init_win32(0, hWnd))
try {
context = std::make_unique<Vulkan::Context>();
if (!context->init_win32(0, hWnd))
return false;
}
catch (std::exception& e)
{
return false;
}
if (GUI.shaderEnabled && GUI.OGLshaderFileName && GUI.OGLshaderFileName[0])
{

View File

@ -107,6 +107,9 @@ returns true if successful, false otherwise
bool WinDisplayReset(void)
{
S9xDisplayOutput->DeInitialize();
if (S9xDisplayOutput == (IS9xDisplayOutput *)&VulkanDriver && GUI.outputMethod == OPENGL)
Sleep(500);
switch(GUI.outputMethod) {
default:
case DIRECT3D:
@ -124,14 +127,23 @@ bool WinDisplayReset(void)
S9xDisplayOutput = &VulkanDriver;
break;
}
if(S9xDisplayOutput->Initialize(GUI.hWnd)) {
bool initialized = S9xDisplayOutput->Initialize(GUI.hWnd);
if (!initialized) {
S9xDisplayOutput->DeInitialize();
Sleep(500);
initialized = S9xDisplayOutput->Initialize(GUI.hWnd);
}
if (initialized) {
S9xGraphicsDeinit();
S9xSetWinPixelFormat ();
S9xSetWinPixelFormat();
S9xGraphicsInit();
if (GUI.DWMSync)
{
HMODULE dwmlib = LoadLibrary(TEXT("dwmapi"));
if (GUI.DWMSync)
{
HMODULE dwmlib = LoadLibrary(TEXT("dwmapi"));
DwmFlushProc = (DWMFLUSHPROC)GetProcAddress(dwmlib, "DwmFlush");
DwmIsCompositionEnabledProc = (DWMISCOMPOSITIONENABLEDPROC)GetProcAddress(dwmlib, "DwmIsCompositionEnabled");