Skip to content

Commit

Permalink
fix: ImHex freezing on AMD GPUs when resizing
Browse files Browse the repository at this point in the history
Fixes #1842
  • Loading branch information
WerWolv committed Jan 1, 2025
1 parent 0e4d949 commit 165403d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions main/gui/source/window/win_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace hex {
static LONG_PTR s_oldWndProc;
static float s_titleBarHeight;
static Microsoft::WRL::ComPtr<ITaskbarList4> s_taskbarList;
static bool s_useLayeredWindow = true;

void nativeErrorMessage(const std::string &message) {
log::fatal(message);
Expand Down Expand Up @@ -644,18 +645,38 @@ namespace hex {
win->fullFrame();
DwmFlush();
});

// AMD GPUs seem to have issues with Layered Window rendering. Until we figure out
// why that is or AMD fixes the issue on their side, disable it on these GPUs.
s_useLayeredWindow = ImHexApi::System::getGPUVendor() != "ATI Technologies Inc.";
}

void Window::beginNativeWindowFrame() {
s_titleBarHeight = ImGui::GetCurrentWindowRead()->MenuBarHeight;

// Remove WS_POPUP style from the window to make various window management tools work
auto hwnd = glfwGetWin32Window(m_window);
::SetWindowLong(hwnd, GWL_STYLE, (GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW) & ~WS_POPUP);
::SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_COMPOSITED | WS_EX_LAYERED);
{
auto style = GetWindowLong(hwnd, GWL_STYLE);
style |= WS_OVERLAPPEDWINDOW;
style &= ~WS_POPUP;

::SetWindowLong(hwnd, GWL_STYLE, style);
}

// Make window composited and layered when supported to eradicate any window flickering that happens while resizing
{
auto style = GetWindowLong(hwnd, GWL_EXSTYLE);
style |= WS_EX_COMPOSITED;

if (s_useLayeredWindow)
style |= WS_EX_LAYERED;

::SetWindowLong(hwnd, GWL_EXSTYLE, style);
}

if (!ImHexApi::System::impl::isWindowResizable()) {
if (glfwGetWindowAttrib(m_window, GLFW_MAXIMIZED)) {
if (glfwGetWindowAttrib(m_window, GLFW_MAXIMIZED) == GLFW_TRUE) {
glfwRestoreWindow(m_window);
}
}
Expand Down

0 comments on commit 165403d

Please sign in to comment.