愚头的博客

一位图形学爱好者的唠叨

记录一次UE4渲染线程崩溃的问题“DXGI ERROR DEVICE REMOVED”

描述

最近在做UE4.26插件时遇到了一个奇怪的渲染崩溃问题。在编辑器模式下,这个插件会自动生成上百个StaticMesh资源,但是生成到190个左右时就会崩溃。

过程

先打开崩溃日志。从整个日志来看,渲染线程出现DXGI_ERROR_DEVICE_REMOVED而导致的崩溃:

crash report

[2021.03.09-11.59.17:899][446]LogRHI: Error: Present Fail Count 1
[2021.03.09-11.59.17:899][446]LogRHI: Error: SyncInterval 0
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferDesc.Width 1620
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferDesc.Height 243
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferDesc.RefreshRate.Numerator 0
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferDesc.RefreshRate.Denominator 0
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferDesc.Format 24
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferDesc.ScanlineOrdering 0
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferDesc.Scaling 0
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.SampleDesc.Count 1
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.SampleDesc.Quality 0
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferUsage 48
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.BufferCount 2
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.OutputWindow 0000000000A8085A
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.Windowed true
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.SwapEffect 4
[2021.03.09-11.59.17:899][446]LogRHI: Error: SwapChainDesc.Flags 2050
[2021.03.09-11.59.17:914][446]LogD3D11RHI: CreateSwapChainForHwnd failed with result 'DXGI_ERROR_DEVICE_REMOVED 00000000' (0x887A0005), falling back to legacy CreateSwapChain.
[2021.03.09-11.59.17:915][446]LogD3D11RHI: Error: CreateSwapChainResult failed 
 at D:/Build/++UE4/Sync/Engine/Source/Runtime/Windows/D3D11RHI/Private/Windows/WindowsD3D11Viewport.cpp:228 
 with error DXGI_ERROR_DEVICE_REMOVED 00000000
[2021.03.09-11.59.17:915][446]LogD3D11RHI: [Aftermath] GDynamicRHI=000002BA37C43200, GDX11NVAfterMathEnabled=0, Result=0xFFFFFFFF, bDeviceActive=0
[2021.03.09-11.59.17:915][446]LogOutputDevice: Warning: 

Script Stack (0 frames):

[2021.03.09-11.59.17:915][446]LogWindows: Windows GetLastError: The operation completed successfully. (0)
[2021.03.09-12.00.01:235][446]LogAudioMixer: Display: Audio Buffer Underrun (starvation) detected.
[2021.03.09-12.00.01:246][446]LogWindows: FPlatformMisc::RequestExit(0)
[2021.03.09-12.00.01:247][446]LogCore: Engine exit requested (reason: Win RequestExit)
[2021.03.09-12.00.01:263][446]LogWindows: FPlatformMisc::RequestExit(1)
[2021.03.09-12.00.01:264][446]LogCore: Engine exit requested (reason: Win RequestExit; note: exit was already requested)
[2021.03.09-12.00.01:270][446]Log file closed, 03/09/21 10:00:01

此时的显存占用也比较高:

gpu device

现在还在用GTX 960M?可怜一下我的GPU😟

切换到DebugGame Editor模式下进行测试,每次都会在这行中断(Github)

UE_LOG(LogD3D11RHI, Fatal, TEXT("Unreal Engine is exiting due to D3D device being lost. D3D device was not available to assertain DXGI cause."));

从上下文看,的确是GPU设备丢失导致运行到这里,但是网上查到的原因很多很难定位,所以还是回到日志里去查。与渲染相关的日志里会出现了这样的ErrorCode

[2021.03.09-11.59.13:452][446]LogD3D11RHI: Timed out while waiting for GPU to catch up. (0.5 s) (ErrorCode 00000001) (00000000)
[2021.03.09-11.59.13:953][446]LogD3D11RHI: Timed out while waiting for GPU to catch up. (0.5 s) (ErrorCode 00000001) (00000000)
[2021.03.09-11.59.14:483][446]LogD3D11RHI: Timed out while waiting for GPU to catch up. (0.5 s) (ErrorCode 00000001) (00000000)
[2021.03.09-11.59.14:982][446]LogD3D11RHI: Timed out while waiting for GPU to catch up. (500 ms)

早在2018年的这篇文章中就出现了同样的问题,然后是Steam社区的文章(需梯子)以及How to Fix the Error ‘Unreal Engine is exiting due to D3D device being lost’。最后一篇最为详细,按照文中所描述的步骤来测试,发现只要将集显禁用掉就没有问题了,其它步骤可以跳过。😄

至此我的插件可以正确运行了🤓,但是问题仍然存在:不知道是UE4的问题还是显卡驱动的问题? 不过现在要赶紧把插件搞好了🤑,待后续有空了再解决。

总结

该问题:

  • 只针对集显+独显的设备
  • 在使用UE4时将集显禁用掉
  • 一直存在,但是还不清楚该UE4还是NVIDIA解决

最近又发现可以将RHI切换到Vulkan渲染,不使用DX11,也不会存在问题👍。