Backends: Vulkan: handle viewport surface creation failure without crashing. (#9068)

This commit is contained in:
zentia
2025-11-14 00:24:44 +08:00
committed by ocornut
parent 707ddd54b6
commit a6645e1007
2 changed files with 16 additions and 2 deletions

View File

@@ -29,6 +29,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
// 2025-11-13: [Docking] Handle viewport surface creation failure without crashing. (#9068)
// 2025-10-15: Vulkan: Added IMGUI_IMPL_VULKAN_VOLK_FILENAME to configure path to volk.h header. (#9008)
// 2025-09-26: *BREAKING CHANGE*: moved some fields in ImGui_ImplVulkan_InitInfo: init_info.RenderPass --> init_info.PipelineInfoMain.RenderPass, init_info.Subpass --> init_info.PipelineInfoMain.Subpass, init_info.MSAASamples --> init_info.PipelineInfoMain.MSAASamples, init_info.PipelineRenderingCreateInfo --> init_info.PipelineInfoMain.PipelineRenderingCreateInfo.
// 2025-09-26: *BREAKING CHANGE*: renamed ImGui_ImplVulkan_MainPipelineCreateInfo to ImGui_ImplVulkan_PipelineInfo. Introduced very recently so shouldn't affect many users.
@@ -1957,7 +1958,6 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
{
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
ImGui_ImplVulkan_ViewportData* vd = IM_NEW(ImGui_ImplVulkan_ViewportData)();
viewport->RendererUserData = vd;
ImGui_ImplVulkanH_Window* wd = &vd->Window;
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
@@ -1966,14 +1966,23 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
VkResult err = (VkResult)platform_io.Platform_CreateVkSurface(viewport, (ImU64)v->Instance, (const void*)v->Allocator, (ImU64*)&wd->Surface);
check_vk_result(err);
// Check if surface creation failed
if (err != VK_SUCCESS || wd->Surface == VK_NULL_HANDLE)
{
IM_DELETE(vd);
return;
}
// Check for WSI support
VkBool32 res;
vkGetPhysicalDeviceSurfaceSupportKHR(v->PhysicalDevice, v->QueueFamily, wd->Surface, &res);
if (res != VK_TRUE)
{
IM_ASSERT(0); // Error: no WSI support on physical device
vkDestroySurfaceKHR(v->Instance, wd->Surface, v->Allocator); // Error: no WSI support on physical device, clean up and return
IM_DELETE(vd);
return;
}
viewport->RendererUserData = nullptr;
// Select Surface Format
ImGui_ImplVulkan_PipelineInfo* pipeline_info = &v->PipelineInfoForViewports;
@@ -2050,6 +2059,8 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
{
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData;
if (vd == nullptr)
return;
ImGui_ImplVulkanH_Window* wd = &vd->Window;
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
VkResult err;
@@ -2197,6 +2208,8 @@ static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*)
{
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData;
if (vd == nullptr)
return;
ImGui_ImplVulkanH_Window* wd = &vd->Window;
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;

View File

@@ -158,6 +158,7 @@ Docking+Viewports Branch:
- Backends:
- DirectX12: Fixed an issue in synchronization logic improving rendering
throughput for secondary viewports. (#9025, #8961)
- Vulkan: handle viewport surface creation failure without crashing. (#9068) [@zentia]
-----------------------------------------------------------------------