From 7794b104c5c6aa0f41680cf527b528f451e7352e Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 29 Jan 2020 11:40:49 +0200 Subject: [PATCH] Backends: SDL/Viewports: Fix crash when SDL backend is used with DirectX graphics API and system does not support Vulkan. We must pass this flag only when we intend to render using vulkan backend. --- examples/imgui_impl_sdl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 32ac4022..8d52a212 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -74,6 +74,7 @@ static bool g_MousePressed[3] = { false, false, false }; static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static char* g_ClipboardTextData = NULL; static bool g_MouseCanUseGlobalState = true; +static bool g_UseVulkan = false; // Forward Declarations static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context); @@ -240,6 +241,7 @@ bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window) #if !SDL_HAS_VULKAN IM_ASSERT(0 && "Unsupported"); #endif + g_UseVulkan = true; return ImGui_ImplSDL2_Init(window, NULL); } @@ -467,7 +469,7 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport) } Uint32 sdl_flags = 0; - sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : SDL_WINDOW_VULKAN; + sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (g_UseVulkan ? SDL_WINDOW_VULKAN : 0); sdl_flags |= SDL_GetWindowFlags(g_Window) & SDL_WINDOW_ALLOW_HIGHDPI; sdl_flags |= SDL_WINDOW_HIDDEN; sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;