Repository navigation
Description
Summary
On Windows hosts with NVIDIA OpenGL, -gpu host leaks WGL pbuffers. Each pbuffer has a hidden
NVOpenGLPbuffer window. After some hours, there are thousands of these windows. Window
operations on the full desktop become slow.
Environment
- Android Emulator 36.4.9 and 37.2.13 (build 16740729).
- Windows 11 (10.0.26300).
- NVIDIA GeForce RTX 4070 Laptop GPU. Drivers 32.0.15.9159 and 32.0.16.2124.
- Guest: API 36.1, google_apis, x86_64.
Steps to reproduce
- Start the emulator in a window with
-gpu host. - Run UI tests that start and stop apps. Continue for some hours.
- In Task Manager, monitor the GDI objects of
qemu-system-x86_64.exe. - Count the top-level windows of class
NVOpenGLPbufferthat the process owns.
Result
The number of windows and GDI objects increases continuously. A framework restart
(adb shell stop; adb shell start) does not decrease it.
| Boot | 8 flows | 16 flows | After restart | |
|---|---|---|---|---|
NVOpenGLPbuffer windows |
68 | 170 | 297 | 293 |
| GDI objects | 137 | 241 | 367 | 362 |
After 13.5 hours: 4,129 windows and 4,251 GDI objects. Moving a window of a different app took
13.8 ms instead of 0.29 ms. HWND_BROADCAST took 4.9 s instead of 0.33 s.
Expected result
The number of pbuffers stays approximately constant.
Cause
host/gl/glestranslator/egl/egl_os_api_wgl.cpp, WglDisplay::releasePbuffer():
if (!winpb->releaseDC()) return false;WinSurface::releaseDC()setsm_hdcto 0 andm_dcReleasedto true. Then it returns the
result ofwglReleasePbufferDC().- If that call fails,
releasePbuffer()returns beforemFreePbufs[...].push_back(pb)and
mLivePbufs[...].erase(pb). - The pbuffer stays in
mLivePbufs. It is not reused and not destroyed. createPbufferSurface()refills an empty pool withmax(live, 8)new pbuffers. Thus, the
pool doubles again and again.
Evidence: we read the WglDisplay containers of a running qemu with ReadProcessMemory. After 8
UI flows, mLivePbufs had 96 pbuffers. Only 20 had a live EglPbufferSurface. The other 76 had
m_dcReleased = 1 and m_hdc = 0. The 37.2.13 DLL has the same code.
We do not know why wglReleasePbufferDC() fails in the emulator. In a test process on the same
host, it did not fail in more than 10,000 calls. #200 reports ERROR_BUSY from WGL calls on a
similar host, because drainGlRenderThreadResources() does not hold m_lock. This can be the
trigger. We did not confirm it.
Proposed fix
Always move the pbuffer to the free list. When the pool gives the pbuffer again, refreshDC()
gets a new DC. If that fails, the pbuffer goes to mDeletePbufs, as before. PR: #239.
Activity