Editor crashes when using diffuse scene texture in expression

This has been a bug since 4.12, keen to get it fixed ASAP as my marketplace users are starting to run into it and it’s a world-ender for the asset they purchased.

If I create a material expression with the following code it crashes:

int TexIndex = 2;
 return SceneTextureLookup(UV, TexIndex, true);

If TexIndex is 2, 5 or 25 it will crash. That’s the diffuse and basecolor buffers. Other postprocess buffers seem fine.

The error occurs on line 427 of Engine/Source/Runtime/Renderer/Private/PostProcess/SceneRenderTargets.h:

/** Get the uniform buffer containing GBuffer resources. */
FUniformBufferRHIParamRef GetGBufferResourcesUniformBuffer() const 
{ 
	// if this triggers you need to make sure the GBuffer is not getting released before (using AdjustGBufferRefCount(1) and AdjustGBufferRefCount(-1))
	// Maybe You use a SceneTexture material expression that should set MaterialCompilationOutput.bNeedsGBuffer
	check(IsValidRef(GBufferResourcesUniformBuffer));

	return GBufferResourcesUniformBuffer; 
}

It seems like someone has done an update in 4.12 and later that ignores the usage commentary above.

Is there a workaround for this? Is there any chance of getting it hotfixed?

Hey -

Can you explain where you’re adding the two lines of code mentioned? Are you creating a class based on MaterialExpression or something else? What function is the code coming from? How is the code/function called? Additionally, can you provide the callstack and log files from the crash for additional information?

In one of these: http://i.imgur.com/Ptp1Lga.png

Sure thing, I’ll send through the log and callstack after I head home tonight. Cheers!

Where is the custom node that you’re using connected to the material(base color, Roughness, Emissive color, etc)? Are you able to reproduce the crash in a new project without additional content? If so, please also provide the steps used that cause the crash

The custom node is in a post-process domain material and is connected to the emissive output. The crash does happen in a fresh project. Here’s one I put together:

https://drive.google.com/open?id=0BxvssEUQL4zbWk4zOFlUc2pDRmM

Select the post-processing volume and make it “unbound” to trigger the crash (or pilot into the PP volume).

Also, if you modify TexIndex to “1” (the scenedepth pass) it stops crashing. So it’s definitely a case of the diffuse buffer being disposed of before the postprocess materials have had a crack at it with custom expressions.

Also, obviously this isn’t the exact use case I use it for, just the simplest example of the crash that I could come up with. Just sampling the scenetexture directly doesn’t solve my problem. :slight_smile:

I was able to figure out a work-around that should also help debug it!

I set up the node graph like this: http://i.imgur.com/8nsNZLE.png

In this case the second DiffuseColor scenetexture is being lerped out to nothing, but since it is referenced the diffuse buffer isn’t disposed of and so is available to the custom expression. This obviously takes up a texture sampler slot but everything runs and there is no crash.

Hey -

I was able to locate a report for this crash occurring previously (Unreal Engine Issues and Bug Tracker (UE-25623) ). I have reopened this report with the information and sample project you provided for further investigation.

Cheers