# Cook Failure - Assertion Failed - !bDeletedThroughDeferredCleanup variable in MaterialShader.cpp

**URL:** <https://forums.unrealengine.com/t/cook-failure-assertion-failed-bdeletedthroughdeferredcleanup-variable-in-materialshader-cpp/439507>\
**Category:** Asset Creation\
**Tags:** packing, assertion-failed, unreal-engine, bug-report, question, Cooking-Failed\
**Created:** [December 15, 2018, 4:20am UTC](https://forums.unrealengine.com/t/cook-failure-assertion-failed-bdeletedthroughdeferredcleanup-variable-in-materialshader-cpp/439507 "2018-12-15T04:20:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaggisu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shaggisu](https://forums.unrealengine.com/u/Shaggisu)\
**Post date:** [December 15, 2018, 4:20am UTC](https://forums.unrealengine.com/t/cook-failure-assertion-failed-bdeletedthroughdeferredcleanup-variable-in-materialshader-cpp/439507/1 "2018-12-15T04:20:19Z")

</div>

We are getting failure while packaging for regular x64 dekstop app,

There are warnings about different shaders that they are **missing cached shader map**

and errors about - Assertion Failed in MaterialShader.cpp, at 2139 line

```
void FMaterialShaderMap::AddRef()
{
	check(!bDeletedThroughDeferredCleanup);
	++NumRefs;
}

```

From what I’ve read in the comments of this structure its responsible for keeping track of material resources and its shader map,

So far we did:

- Fixed redirectors,
- Tried deleting Saved and Intermediate
- Generated DDC data
- we are looking through materials and material instances deleting loose nodes, looking for errors itd.
- checking map, deleting unnecessary files from content browser and map
- validated data

It’s on version 4.20 we’ve done quiet a lot of work already fixing up this error but still couldn’t overcome it  
We would appreciate any help and suggestions on dealing with it.

* * *

Log from Cook.txt in appdata:

```
LogMaterial: Display: Missing cached shader map for material master_default_with_snow, compiling. 
LogMaterial: Display: Missing cached shader map for material master_landscape_spline_road, compiling. 
LogMaterial: Display: Missing cached shader map for material master_blend_m, compiling. 
LogShaderCompilers: Display: Shaders left to compile 2337
LogShaderCompilers: Display: Shaders left to compile 2327
LogShaderCompilers: Display: Shaders left to compile 2317
LogShaderCompilers: Display: Shaders left to compile 2307
LogWindows: Windows GetLastError: Operacja ukończona pomyślnie. (0)
LogShaderCompilers: Display: Shaders left to compile 2297
LogWindows: Error: begin: stack for UAT
LogWindows: Error: === Critical error: ===
LogWindows: Error: 
LogWindows: Error: Assertion failed: !bDeletedThroughDeferredCleanup [File:D:\Build\++UE4\Sync\Engine\Source\Runtime\Engine\Private\Materials\MaterialShader.cpp] [Line: 2139] 
LogWindows: Error: 
LogWindows: Error: 
LogWindows: Error: 
LogWindows: Error: [Callstack] 0x00007ffb0348a388 KERNELBASE.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffaf0026850 UE4Editor-ApplicationCore.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffada3a62fc UE4Editor-Core.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffada3351db UE4Editor-Core.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffac3c6d7a1 UE4Editor-Engine.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffac3c79e32 UE4Editor-Engine.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffac3c7ac2c UE4Editor-Engine.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffac3c7973c UE4Editor-Engine.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffac3c78061 UE4Editor-Engine.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffac3cc02da UE4Editor-Engine.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffac3cc060e UE4Editor-Engine.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffadc983345 UE4Editor-CoreUObject.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffadca6b7a1 UE4Editor-CoreUObject.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffadca862c4 UE4Editor-CoreUObject.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffadca854b9 UE4Editor-CoreUObject.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffad7110b3c UE4Editor-UnrealEd.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffad715553d UE4Editor-UnrealEd.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffad6fc7a8d UE4Editor-UnrealEd.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffad6ff88ff UE4Editor-UnrealEd.dll!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ff6a409e9c2 UE4Editor-Cmd.exe!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ff6a4095968 UE4Editor-Cmd.exe!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ff6a4095bba UE4Editor-Cmd.exe!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ff6a40a3dac UE4Editor-Cmd.exe!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ff6a40a4ce6 UE4Editor-Cmd.exe!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffb05793034 KERNEL32.DLL!UnknownFunction []
LogWindows: Error: [Callstack] 0x00007ffb06671471 ntdll.dll!UnknownFunction []
LogWindows: Error: 
LogWindows: Error: end: stack for UAT
LogExit: Executing StaticShutdownAfterError
LogWindows: FPlatformMisc::RequestExit(1)
Log file closed, 12/14/18 16:47:40
```

---

<div class="post-metadata">

**Author:** ![Ultium](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ultium](https://forums.unrealengine.com/u/Ultium)\
**Post date:** [March 22, 2019, 11:31am UTC](https://forums.unrealengine.com/t/cook-failure-assertion-failed-bdeletedthroughdeferredcleanup-variable-in-materialshader-cpp/439507/2 "2019-03-22T11:31:46Z")

</div>

Have you find any workaround ?

---

<div class="post-metadata">

**Author:** ![Ultium](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ultium](https://forums.unrealengine.com/u/Ultium)\
**Post date:** [April 10, 2019, 10:04am UTC](https://forums.unrealengine.com/t/cook-failure-assertion-failed-bdeletedthroughdeferredcleanup-variable-in-materialshader-cpp/439507/3 "2019-04-10T10:04:00Z")

</div>

I had this problem too.

For me For me it comes from materials layers.  
I need to force recompile the base material before **each** packaging  
 ![](https://i.imgur.com/qhUmPcA.png)

and i have to make sure there are no material instance that have the same combination of layers and layer blend.

**Material instance 1** : Layer A _with_ Blend A | Background B

**Material instance 2** : Layer A _with_ Blend A | Background B

cause a crash

* * *

**Material instance 1** : Layer A _with_ Blend A | Background B

**Material instance 2** : Layer A _with_ **Copy** Blend A | Background B

does not cause a crash.
