App crash on first launch: shader compilation on a fresh machine

Your stream test passed with a warning: the app crashed the first time it started, and ran when it was started again. Your app works — but its first start on a fresh machine is heavy enough to fall over. This page explains what an Unreal app does when it first starts, why that can crash on a streaming machine, what our system does about it, and how to make the first start smooth.

In short

What the warning means for you
Stream test resultWhat it meansWhat to do
PassedThe app started and streamed on the first tryNothing
Passed with a warning: crashed on launch 1 (or 1 and 2), ran on the nextThe first start on a fresh machine is too heavy. Viewers who are first on a machine can hit the same crashPackage your shader pipeline cache with the build (How to fix it)
Failed: crashed on all 3 launchesThe app does not start on our machines at allA different problem: see the crash details in the test result, or test it on your own PC

What an Unreal app does when it first starts

Shaders and pipeline states

A shader is a small program that runs on the graphics card and decides how every surface, light and effect looks. A game has thousands of them. When you package your project, Unreal compiles them into a shader library that ships with the build.

That is not the end of the work. Before the graphics card can draw with a shader, the graphics driver has to turn it into a pipeline state (PSO) for that exact graphics card and driver. On DirectX 12 and Vulkan this happens while the app runs, and the driver keeps the result in a cache on the machine. The first start on a machine has an empty cache, so the app creates hundreds or thousands of pipeline states at once: the processor, the graphics card and memory are all working hard for the first seconds or minutes. From the second start on, the driver reads them from its cache and the start is much lighter.

On your own PC you rarely notice: you started the game many times, your cache is warm. A streaming machine that has never run your build starts cold.

Why that can crash

Heavy work at the worst moment
  • Memory spikes: building many pipeline states while the first level loads can run out of graphics or system memory.
  • Graphics card timeout: if the card is busy too long in one go, Windows resets the driver (a "TDR"), and the app crashes with a device-removed error.
  • Everything at once: loading the map, compiling, and starting the stream all happen in the same first seconds.

The second start has less to do, which is why it works.

What our system does

It recovers - but viewers notice
  • Stream test: a crash on start is retried — up to 3 launches in total. If launch 2 or 3 works, the test passes with this warning; if all 3 crash, the test fails.
  • Live viewers: if your app crashes while a viewer is starting a session, our system starts it again and connects the viewer on the next attempt.

So your viewers do get the stream — but the one who is first on a machine waits through a crash and a restart. It works, and it is an unpleasant first impression. Each streaming machine starts cold the first time it runs your build, so this can happen more than once.

How to fix it

Ship the pipeline cache with your build
  1. Record the pipeline states your app uses. Run a packaged build with -logPSO, play through your main levels and views, and close the app. Unreal writes recorded .rec.upipelinecache files in the project's Saved/CollectedPSOs folder.
  2. Turn them into a bundled cache. Use the ShaderPipelineCacheTools commandlet (expand) with the shader info files from the cook, and put the resulting .spc file in Build/Windows/PipelineCaches in your project.
  3. Package again. The cache is included in the build; at start the app compiles the pipeline states from it in the background, before they are needed, instead of all at once on first draw.
  4. On Unreal 5.1 and newer, also check that PSO precaching is on (r.PSOPrecaching=1, default in recent versions); it creates pipeline states while assets load instead of on first use.
  5. Give the first start breathing room: show a loading screen and let shaders compile before heavy gameplay starts; avoid loading the biggest level directly at start.

Unreal's documentation calls this "PSO caching" (bundled PSO cache and PSO precaching); search for those terms for your engine version — the exact steps differ slightly between versions.

Check it on your own PC

Make your PC start cold
  1. Close the app.
  2. Clear the graphics driver's shader cache (for NVIDIA: the DXCache folder under %LOCALAPPDATA%\NVIDIA; Windows Disk Cleanup also offers "DirectX Shader Cache").
  3. Start the packaged build. If it hitches heavily or crashes now and runs on the next start, you are seeing the same first-start problem.
  4. Fix it as above, clear the cache again, and confirm the first start is smooth.

Need help?

Send us the stream test result from the upload window, and we will look at the crash details from each launch with you.

Related

Last updated