# UE Crashes when using compute shaders

**URL:** <https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 21, 2014, 5:49pm UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841 "2014-10-21T17:49:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 21, 2014, 5:49pm UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/1 "2014-10-21T17:49:47Z")

</div>

Hello everyone.

I’m using compute shaders to deform a mesh. I’m having a consistent crash when running/compiling my code:

```
Assertion failed: !bInitializedSerializationHistory [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.5\Engine\Source\Runtime\ShaderCore\Private\Shader.cpp] [Line: 93] 

```

Usually this appears if I don’t set my project’s LoadingPhase to “PostConfigInit”. However, I have already done this. The editor opens and I can run my project fine. Problem is when I make changes to my code and have to recompile. Directly compiling through the editor crashes after a while. Compiling through Visual Studio only works if I open the editor, make it crash on purpose, and reopen afterwards. Only then does it apply the changes made.

I’m not posting my code right now because its fairly long, and I figured there could be some basic stuff that I’m missing. If that’s not the case, I’ll try to supply at least a sample of the code that I think might be causing the problem.

Thanks!

---

<div class="post-metadata">

**Author:** ![Ehamloptiran\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ehamloptiran\_1](https://forums.unrealengine.com/u/Ehamloptiran_1)\
**Post date:** [October 22, 2014, 5:08am UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/2 "2014-10-22T05:08:55Z")

</div>

Im just taking a stab here since the error is in regards to bInitializedSerialiationHistory. Do your compute shaders have bound parameters? ie you call Parameter.Bind in the constructor? If so, are you serializing those parameters? I’ve noticed not doing that can potentially cause crashes.

---

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 22, 2014, 8:08am UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/3 "2014-10-22T08:08:04Z")

</div>

The answer is “yes” to all your questions. In that regard I’m doing almost exactly what you’re doing in your FluidSurface plugin.

---

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 22, 2014, 8:24am UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/4 "2014-10-22T08:24:23Z")

</div>

Actually, let me be a bit more detailed, while also providing some of my own suspicions:

Here’s the code that dispatches the compute shader. In 4.5 I got an error in GetGlobalShaderMap, so I worked around it using GetMaxRHIFeatureLevel(), as can be seen below:

```
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
	Compute,
	FUnorderedAccessViewRHIRef&, data_uav, data_uav,
	dreng_cs_params&, parameters, parameters,
	{

	TShaderMapRef<FDrengCS> test_cs(GetGlobalShaderMap(GetMaxRHIFeatureLevel()));
	//TShaderMapRef<FDrengCS> test_cs(GetGlobalShaderMap());
	
	FComputeShaderRHIParamRef cs_ref = test_cs->GetComputeShader();

	RHICmdList.SetComputeShader(cs_ref);

	if (test_cs->RWBuffer.IsBound()){
		RHICmdList.SetUAVParameter(cs_ref, test_cs->RWBuffer.GetBaseIndex(), data_uav);
	}

	test_cs->set_uniform_buffers(RHICmdList, parameters);

	RHICmdList.DispatchComputeShader(32, 32, 1);

	test_cs->unbind_buffers(RHICmdList);
	
	}
);

```

Another possible reason for the crash is that I’m using this code directly in the Tick function of an Actor. Could there be some limitation in that aspect?

---

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 23, 2014, 3:14pm UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/5 "2014-10-23T15:14:05Z")

</div>

After attacking this issue again, I’ve found out that the very definition of the Global Shader is enough to make the editor crash on compilation. I’m not even using it!

Truth is, this code isn’t within a module or a plugin, it is in the same source folder as all the other code. Is that what might be wrong? Does this global shader NEED to be in a plugin or module that has the PostConfigInit option? I had hoped that placing it in the .uproject file would be enough.

Anyway, I’m attaching the code that causes problems. I don’t see anything wrong with it, so I’m assuming its the PostConfigInit thing, but one may never know.

---

<div class="post-metadata">

**Author:** ![Ehamloptiran\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ehamloptiran\_1](https://forums.unrealengine.com/u/Ehamloptiran_1)\
**Post date:** [October 24, 2014, 5:22am UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/6 "2014-10-24T05:22:51Z")

</div>

So do you have PostConfigInit option defined anywhere? in the .uproject? In an additional module? If not, then you will need to, simplest solution is to add it to the uproject. Best solution is separate out the Compute Shader class into another module that has PostConfigInit set and execute the Compute Shader from your main module as per normal. Thats how my Fluid Surface plugin is setup.

---

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 24, 2014, 8:43am UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/7 "2014-10-24T08:43:19Z")

</div>

I do have it defined in the uproject. As I said, its really weird that it only crashes when I compile from the editor, because it DOES run. I have tried doing it in a separate module and setting it as PostConfigInit, but still didn’t work.

---

<div class="post-metadata">

**Author:** ![Ehamloptiran\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ehamloptiran\_1](https://forums.unrealengine.com/u/Ehamloptiran_1)\
**Post date:** [October 24, 2014, 1:10pm UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/8 "2014-10-24T13:10:22Z")

</div>

Hmm… I will setup a test project over the weekend and see if I can repro this issue. I will keep you posted.

---

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 24, 2014, 2:34pm UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/9 "2014-10-24T14:34:33Z")

</div>

Oh, thanks! If you need any aditional information just let me know. 🙂

---

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 28, 2014, 10:35am UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/10 "2014-10-28T10:35:15Z")

</div>

I’m posting a minimalist sample project which is enough to demonstrate the crash.

A few notes:

- Remember to place the .usf file in your engine shaders folder.
- If it seems to compile fine, change something in the code and make it recompile FROM THE EDITOR (if done in Visual Studio it compiles fine). Then it should crash.

Many thanks in advance if someone has the patience to check this out. 🙂

---

<div class="post-metadata">

**Author:** ![Ehamloptiran\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ehamloptiran\_1](https://forums.unrealengine.com/u/Ehamloptiran_1)\
**Post date:** [October 28, 2014, 12:44pm UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/11 "2014-10-28T12:44:07Z")

</div>

Okay this problem is because of hot reload. The module needs to be loaded prior to a specific point during startup, which does happen, but when a hot reload occurs after an in editor compile, the module is reloaded immediately, causing the engine to crash, this is correct behavior, in the sense that a module that needs to be loaded PostConfigInit to allow the shader type to be registered, which cannot happen during runtime of the editor, but maybe it shouldn’t crash but warn the user and not reload the shader or something along those lines.

I was able to get around this crash by creating a secondary module (CrashTestEngine in this case) and moved the CS class into that module, set that module to PostConfigInit and the main module to Default. When you change something in the main module and recompile from editor, it will work fine. This means if you want to change something in the secondary module, you will need to exit the editor and recompile from VS.

---

<div class="post-metadata">

**Author:** ![dsl\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dsl\_1](https://forums.unrealengine.com/u/dsl_1)\
**Post date:** [October 28, 2014, 2:29pm UTC](https://forums.unrealengine.com/t/ue-crashes-when-using-compute-shaders/296841/12 "2014-10-28T14:29:20Z")

</div>

Yup, that worked! At least now I can compile from the editor, although when i compile from VS I would expect hot reload to work, but it crashes as before. I’m assuming that’s an error on my part, since I might have done something wrong when creating the module.

Thanks for everything Ehamloptiran!
