x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

UE Crashes when using compute shaders

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!

Product Version: Not Selected
Tags:
more ▼

asked Oct 21 '14 at 05:49 PM in Rendering

avatar image

dsl
48 3 6 8

avatar image dsl Oct 23 '14 at 03:14 PM

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.

header.txt (1.0 kB)
source.txt (1.5 kB)
avatar image Ehamloptiran Oct 24 '14 at 05:22 AM

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.

avatar image dsl Oct 24 '14 at 08:43 AM

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.

avatar image Ehamloptiran Oct 24 '14 at 01:10 PM

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

avatar image dsl Oct 24 '14 at 02:34 PM

Oh, thanks! If you need any aditional information just let me know. :-)

avatar image dsl Oct 28 '14 at 10:35 AM

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. :-)

crashtest.zip (584.5 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Oct 28 '14 at 12:44 PM

avatar image

Ehamloptiran
1.5k 50 9 59

avatar image dsl Oct 28 '14 at 02:29 PM

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!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Oct 22 '14 at 05:08 AM

avatar image

Ehamloptiran
1.5k 50 9 59

avatar image dsl Oct 22 '14 at 08:08 AM

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

avatar image dsl Oct 22 '14 at 08:24 AM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question