# Editor crashes when using diffuse scene texture in expression

**URL:** <https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546>\
**Category:** Rendering\
**Tags:** unreal-engine, crash, editor, question\
**Created:** [September 6, 2016, 10:18am UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546 "2016-09-06T10:18:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antidamage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/antidamage/32/918692_2.png) [@Antidamage](https://forums.unrealengine.com/u/Antidamage)\
**Post date:** [September 6, 2016, 10:18am UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546/1 "2016-09-06T10:18:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [September 6, 2016, 7:36pm UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546/2 "2016-09-06T19:36:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Antidamage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/antidamage/32/918692_2.png) [@Antidamage](https://forums.unrealengine.com/u/Antidamage)\
**Post date:** [September 6, 2016, 7:44pm UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546/3 "2016-09-06T19:44:33Z")

</div>

In one of these: [http://i.imgur.com/Ptp1Lga.png](http://i.imgur.com/Ptp1Lga.png)

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [September 6, 2016, 8:39pm UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546/4 "2016-09-06T20:39:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Antidamage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/antidamage/32/918692_2.png) [@Antidamage](https://forums.unrealengine.com/u/Antidamage)\
**Post date:** [September 6, 2016, 8:58pm UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546/5 "2016-09-06T20:58:18Z")

</div>

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](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. 🙂

---

<div class="post-metadata">

**Author:** ![Antidamage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/antidamage/32/918692_2.png) [@Antidamage](https://forums.unrealengine.com/u/Antidamage)\
**Post date:** [September 6, 2016, 10:16pm UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546/6 "2016-09-06T22:16:33Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [September 8, 2016, 5:15pm UTC](https://forums.unrealengine.com/t/editor-crashes-when-using-diffuse-scene-texture-in-expression/369546/7 "2016-09-08T17:15:21Z")

</div>

Hey -

I was able to locate a report for this crash occurring previously ([Unreal Engine Issues and Bug Tracker (UE-25623)](https://issues.unrealengine.com/issue/UE-25623) ). I have reopened this report with the information and sample project you provided for further investigation.

Cheers
