Skip to content

Fix client hang after hibernate: D3D9 device recovery and lost device timeout#779

Draft
Copilot wants to merge 2 commits intocore4from
copilot/fix-client-hang-after-hibernate
Draft

Fix client hang after hibernate: D3D9 device recovery and lost device timeout#779
Copilot wants to merge 2 commits intocore4from
copilot/fix-client-hang-after-hibernate

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

After Windows hibernate/sleep, the client spins indefinitely in the main loop logging "lost device" and never recovers or disconnects. The D3D9 device stays in D3DERR_DEVICELOST state permanently.

D3D driver: proper lost device recovery (driver_direct3d.cpp)

swapBuffers() was calling Present() on an already-lost device each frame, which cannot properly detect the transition to D3DERR_DEVICENOTRESET. Now when _Lost is true, we skip rendering and directly poll TestCooperativeLevel():

if (_Lost)
{
    HRESULT hr = _DeviceInterface->TestCooperativeLevel();
    if (hr == D3DERR_DEVICENOTRESET)
    {
        reset (_CurrentMode);
    }
    return !_Lost;
}

This is the standard D3D9 device recovery pattern — avoid all rendering calls on a lost device and wait for the reset-ready state.

Main loop: 30s timeout for unrecoverable device loss (main_loop.cpp)

  • Tracks elapsed time in lost state; forces NetMngr.disconnect() and exits the main loop after 30 seconds
  • Timer resets if the device recovers normally
  • Prevents permanent hang when the device never transitions out of lost state (e.g. post-hibernate with stale graphics state)
Original prompt

This section details on the original issue you should resolve

<issue_title>Client hangs after hibernate on Windows 10</issue_title>
<issue_description>```
2020/11/01 15:03:03 DBG 5078 ryzom_client_dev_r.exe network_connection.cpp 2512 CNetworkConnection::decodeHeader : CNET[00007FF7C5631EB0] lost messages server->client [50836; 50836]
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:04 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:05 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:06 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:07 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:07 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:07 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost device
2020/11/01 15:03:07 DBG 5078 ryzom_client_dev_r.exe main_loop.cpp 2309 mainLoop : lost d...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… device timeout

When the D3D device is already lost, skip rendering operations (endScene,
Present) and directly check TestCooperativeLevel() for recovery. This follows
the standard D3D9 device recovery pattern.

Also add a 30-second timeout in the main loop: if the device stays lost
without recovery, force disconnect to prevent indefinite hang.

Co-authored-by: kaetemi <1581053+kaetemi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix client hangs after hibernate on Windows 10 Fix client hang after hibernate: D3D9 device recovery and lost device timeout Feb 14, 2026
Copilot AI requested a review from kaetemi February 14, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Client hangs after hibernate on Windows 10

2 participants