Skip to content

Crashing when dragging imgui window out of the main window #8713

@Mairooriam

Description

@Mairooriam

Version/Branch of Dear ImGui:

Version v1.91.9b, Branch: docking

Back-ends:

imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp

Compiler, OS:

Windows 11 + GCC 14.2.0

Full config/build information:

Dear ImGui 1.92.0 WIP (19199)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=202302
define: _WIN32
define: _WIN64
define: __MINGW32__
define: __MINGW64__
define: __GNUC__=14
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw (3310)
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000483
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
io.ConfigDpiScaleFonts
io.ConfigDpiScaleViewports
io.ConfigViewportsNoDecoration
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C1E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasTextures
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.Fonts->FontLoaderName: stb_truetype
io.DisplaySize: 1280.00,800.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

Crashing when dragging imgui window outside the main window.

I started working on my project after a break and i thought viewports had worked, but it kept crashing. I tried to look for fix for quite some time and it ended up being glfw version. Switching from glfw 3.3.9 to glfw 3.4 fixed it. Making this issue post to find what's causing the crash with glfw older version, since from going trough posts about imgui it seems like it has been working with 3.x.x. also i couldn't find any other issues refering to imgui_impl_glfw.cpp:1501.

imgui_impl_glfw.cpp at line 1501 ( ImGuiIO& io = ImGui::GetIO(bd->Context); ) is where the program is crashing. It appears that the GetPropA.

static LRESULT CALLBACK ImGui_ImplGlfw_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    ImGui_ImplGlfw_Data* bd = (ImGui_ImplGlfw_Data*)::GetPropA(hWnd, "IMGUI_BACKEND_DATA");
    ImGuiIO& io = ImGui::GetIO(bd->Context);
...
Rest of the implementation
...

Callstack

ImGui_ImplGlfw_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) (c:\Users\35850\Desktop\testing\build\_deps\imgui-src\backends\imgui_impl_glfw.cpp:1501)
user32.dll!USER32!DispatchMessageW (Unknown Source:0)
user32.dll!USER32!DispatchMessageW (Unknown Source:0)
user32.dll!USER32!GetClassLongW (Unknown Source:0)
ntdll.dll!ntdll!KiUserCallbackDispatcher (Unknown Source:0)
win32u.dll!win32u!NtUserShowWindow (Unknown Source:0)
_glfwPlatformShowWindow(_GLFWwindow * window) (c:\Users\35850\Desktop\testing\build\_deps\glfw-src\src\win32_window.c:1777)
glfwShowWindow(GLFWwindow * handle) (c:\Users\35850\Desktop\testing\build\_deps\glfw-src\src\window.c:761)
ImGui_ImplGlfw_ShowWindow(ImGuiViewport * viewport) (c:\Users\35850\Desktop\testing\build\_deps\imgui-src\backends\imgui_impl_glfw.cpp:1307)
ImGui::UpdatePlatformWindows() (c:\Users\35850\Desktop\testing\build\_deps\imgui-src\imgui.cpp:16985)
main() (c:\Users\35850\Desktop\testing\example.cpp:220)

thanks for help in advance!

Screenshots/Video:

Variables at the time of the crash
Variables at the time of crash

Minimal, Complete and Verifiable Example code:

Building original example with the cmakelists.txt below:

// Original examples/example_glfw_opengl3/main.cpp
cmake_minimum_required(VERSION 3.10)
project(testing VERSION 0.1.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

include(FetchContent)

FetchContent_Declare(
  glfw
  GIT_REPOSITORY https://github.com/glfw/glfw.git
  GIT_TAG 3.3.10
)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(glfw)

FetchContent_Declare(
  imgui
  GIT_REPOSITORY https://github.com/ocornut/imgui.git
  GIT_TAG docking
)

FetchContent_MakeAvailable(imgui)

add_library(imgui STATIC
  ${imgui_SOURCE_DIR}/imgui.cpp
  ${imgui_SOURCE_DIR}/imgui_draw.cpp
  ${imgui_SOURCE_DIR}/imgui_widgets.cpp
  ${imgui_SOURCE_DIR}/imgui_tables.cpp
  ${imgui_SOURCE_DIR}/imgui_demo.cpp
  ${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
  ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
  ${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
)

target_include_directories(imgui PUBLIC
  ${imgui_SOURCE_DIR}
  ${imgui_SOURCE_DIR}/backends
  ${imgui_SOURCE_DIR}/misc/cpp
)

find_package(OpenGL REQUIRED)
target_link_libraries(imgui PUBLIC glfw OpenGL::GL)

add_executable(example example.cpp)

target_link_libraries(example PRIVATE imgui glfw OpenGL::GL)

target_include_directories(example PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}/include
)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions