win32: fix crash when switching to vulkan

fix recursive call to VulkanContext::Init
still crashing when starting with vk and switching to GL
This commit is contained in:
flyinghead 2020-01-08 10:58:24 +01:00
parent efdc92479a
commit 36a7c00507
3 changed files with 20 additions and 9 deletions

View File

@ -668,7 +668,8 @@ bool VulkanContext::Init()
extensions.resize(extensionsCount + 1);
SDL_Vulkan_GetInstanceExtensions((SDL_Window *)window, &extensionsCount, &extensions[1]);
#elif defined(_WIN32)
os_CreateWindow();
extern void CreateMainWindow();
CreateMainWindow();
extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
#elif defined(__MACH__)
extensions.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
@ -865,6 +866,10 @@ void VulkanContext::Term()
#endif
#endif
instance.reset();
#ifdef _WIN32
extern void DestroyMainWindow();
DestroyMainWindow();
#endif
}
void VulkanContext::DoSwapAutomation()

View File

@ -382,11 +382,8 @@ static HWND hWnd;
static bool windowClassRegistered;
static int window_x, window_y;
void os_CreateWindow()
void CreateMainWindow()
{
#if defined(USE_SDL)
sdl_window_create();
#else
if (hWnd != NULL)
return;
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(0);
@ -425,11 +422,19 @@ void os_CreateWindow()
#endif
theGLContext.SetWindow(hWnd);
theGLContext.SetDeviceContext(GetDC(hWnd));
}
void os_CreateWindow()
{
#if defined(USE_SDL)
sdl_window_create();
#else
CreateMainWindow();
InitRenderApi();
#endif // !USE_SDL
}
void DestroyWindow()
void DestroyMainWindow()
{
if (hWnd)
{

View File

@ -23,7 +23,8 @@
#include "oslib/oslib.h"
#if defined(_WIN32) && !defined(USE_SDL)
void DestroyWindow();
void CreateMainWindow();
void DestroyMainWindow();
WGLGraphicsContext theGLContext;
@ -37,7 +38,7 @@ bool WGLGraphicsContext::Init()
// Already initialized
return true;
os_CreateWindow();
CreateMainWindow();
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
@ -137,7 +138,7 @@ void WGLGraphicsContext::Term()
wglMakeCurrent(ourWindowHandleToDeviceContext, NULL);
wglDeleteContext(ourOpenGLRenderingContext);
ourOpenGLRenderingContext = NULL;
DestroyWindow();
DestroyMainWindow();
}
}