Description

RHIinit() calls GRHICommandList.GetImmediateCommandList().GetContext() to make sure that GDynamicRHI->Init() initialized the immediate command list (by calling FRHICommandListImmediate::InitializeImmediateContexts()). This works in Debug and Development because the lambda enqueued by SwitchPipeline runs immediately, as Bypass() returns true before the RHI thread is started. However, in Test and Shipping Bypass() always returns false, so the switch pipelines command is enqueued rather than executed, and nothing sets up the contexts on the immediate command list.

However, checks are normally disabled in Test and Shipping, so the checkf() inside GetContext() doesn't fire. Two wrongs make a right in this case. :> When USE_CHECKS_IN_SHIPPING is 1, the check fires, and the engine crashes on startup.

Note that this doesn't happen in server builds because RHIInit takes a different path (it uses the null RHI and doesn't perform this check).

We either need to flush commands before calling GetContext(), or we need to find another way of ensuring that the dynamic RHI has called InitializeImmediateContexts().

Steps to Reproduce

Download the licensee repro from here:
[Link Removed]

Compile a Win64 test package of the project (either via the editor or buildcookrun etc)

Launch the test package. If using Visual Studio, launch Test/Win64/TestProjectUDN. Crash occurs on startup.

Alternative steps:

  • Define USE_CHECKS_IN_SHIPPING to 1 in Engine/Source/Runtime/Core/Public/Misc/Build.h or set bUseChecksInShipping to true in the build script for the project.
  • Compile any project in the Test Client or Shipping Client configuration. Make sure you also cook, so you can run it.
  • Run the client, observe assertion failure on startup in RHIInit():
    Assertion failed: GraphicsContext [File:Engine\Source\Runtime\RHI\Public\RHICommandList.h] [Line: 581] 
    There is no active graphics context on this command list. There may be a missing call to SwitchPipeline().
    
Callstack
Assertion failed: GraphicsContext [File:D:\Unreal\UE5_Release-5.1\Engine\Source\Runtime\RHI\Public\RHICommandList.h] [Line: 581] 
There is no active graphics context on this command list. There may be a missing call to SwitchPipeline().
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in TestProjectUDN-Win64-Test.exe.

>    [Inline Frame] TestProjectUDN-Win64-Test.exe!FRHICommandListBase::GetContext() Line 581    C++
     TestProjectUDN-Win64-Test.exe!RHIInit(bool bHasEditorToken) Line 347    C++
     [Inline Frame] TestProjectUDN-Win64-Test.exe!FCpuProfilerTrace::FEventScope::{ctor}(unsigned int &) Line 120    C++
     TestProjectUDN-Win64-Test.exe!FEngineLoop::PreInitPreStartupScreen(const wchar_t * CmdLine) Line 2814    C++
     [Inline Frame] TestProjectUDN-Win64-Test.exe!FEngineLoop::PreInit(const wchar_t *) Line 3939    C++
     [Inline Frame] TestProjectUDN-Win64-Test.exe!EnginePreInit(const wchar_t *) Line 46    C++
     TestProjectUDN-Win64-Test.exe!GuardedMain(const wchar_t * CmdLine) Line 154    C++
     TestProjectUDN-Win64-Test.exe!LaunchWindowsStartup(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow, const wchar_t * CmdLine) Line 233    C++
     TestProjectUDN-Win64-Test.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * pCmdLine, int nCmdShow) Line 282    C++
     [External Code]    

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-171275 in the post.

0
Login to Vote

Unresolved
ComponentUE - Rendering - RHI
Affects Versions5.1
Target Fix5.2
CreatedNov 29, 2022
UpdatedJan 26, 2023