Skip to content

Main viewport has wrong ImDrawData.DisplaySize after window resize when multi-viewports are disabled #4900

@theomonnom

Description

@theomonnom

Version/Branch of Dear ImGui:

Version: 1.87 (18604)
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl.cpp + imgui_impl_wgpu.cpp
Compiler: GCC 11.2.0 x86_64-linux-gnu
Operating System: Ubuntu 21.10 X11

My Issue/Question:

When I resize the window, the ImDrawData struct obtained using ImGui::GetDrawData() has the wrong DisplaySize (by wrong I mean it has not been updated)
This is a strange behavior because ImGui_ImplSDL2_NewFrame updates io.DisplaySize to the new frame size and ImGui_ImplSDL2_ProcessEvent updates viewport->PlatformRequestResize to true. (Note that multi-viewport isn't enabled, only docking is enabled). This causes the application to crash on the WGPU backend because the framebuffer is smaller than the requested size.
io.DisplayFramebufferScale is always (1; 1) in my case.

Example:
On Event:

ImGui_ImplSDL2_ProcessEvent(&event); // viewport->PlatformRequestResize is successfully updated

Main Loop:

ImGui_ImplSDL2_NewFrame(); // io.DisplaySize is successfully updated
ImGui_ImplWGPU_NewFrame();

ImGui::NewFrame();
ImGui::ShowDemoWindow();
ImGui::Render();

ImGui_ImplWGPU_RenderDrawData(ImGui::GetDrawData(), renderPassEnc); // GetDrawData has wrong DisplaySize here

Workaround:
The workaround I found is to remove this condition in AddUpdateViewport: (I hope it will help)

if (!viewport->PlatformRequestMove)
   viewport->Pos = pos;
// if (!viewport->PlatformRequestResize) Removed
viewport->Size = size;
viewport->Flags = flags | (viewport->Flags & ImGuiViewportFlags_Minimized); // Preserve existing flags

EDIT: I think this issue occurs in whatever backend

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions