Assert failure when creating new material node

Steps to reproduce.

  1. Create a third person C++ project. All defaults.
  2. Select ThirdPersonCharacter in the World Outliner tab.
  3. Double click the Skeletal Mesh icon to bring up the material editor.
  4. Click the + icon next to Material Slots to add a material slot.
  5. On the dropdown on the new Material, select Material under Create New Asset.
  6. Click save. Location doesn’t matter.
  7. Double click the new material icon to get into the node editor.
  8. Add a TextureSampleParamater2D node.
  9. Watch it crash.

The problem is that the Render Thread is trying to finish up some shader compilation when it creates an FCanvas. This FCanvas tries to access this shader resource, but there are asserts around all shader resource access to ensure that only the game thread can access shader resources.

Here is a stack trace:

UE4Editor-ShaderCore-Win64-Debug.dll!FShaderResource::FindShaderResourceById(const FShaderResourceId & Id) Line 551	C++
UE4Editor-ShaderCore-Win64-Debug.dll!FShaderResource::FindOrCreateShaderResource(const FShaderCompilerOutput & Output, FShaderType * SpecificType) Line 560	C++
UE4Editor-Engine-Win64-Debug.dll!FMeshMaterialShaderType::FinishCompileShader(const FUniformExpressionSet & UniformExpressionSet, const FSHAHash & MaterialShaderMapHash, const FShaderCompileJob & CurrentJob, const FShaderPipelineType * ShaderPipelineType, const FString & InDebugDescription) Line 127	C++
UE4Editor-Engine-Win64-Debug.dll!FMaterialShaderMap::ProcessCompilationResultsForSingleJob(FShaderCompileJob * SingleJob, const FShaderPipelineType * ShaderPipeline, const FSHAHash & MaterialShaderMapHash) Line 1447	C++
UE4Editor-Engine-Win64-Debug.dll!FMaterialShaderMap::ProcessCompilationResults(const TArray<FShaderCommonCompileJob *,FDefaultAllocator> & InCompilationResults, int & InOutJobIndex, float & TimeBudget, TMap<FVertexFactoryType const *,TArray<FShaderPipelineType const *,FDefaultAllocator>,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<FVertexFactoryType const *,TArray<FShaderPipelineType const *,FDefaultAllocator>,0> > & SharedPipelines) Line 1487	C++
UE4Editor-Engine-Win64-Debug.dll!FShaderCompilingManager::ProcessCompiledShaderMaps(TMap<int,FShaderMapFinalizeResults,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<int,FShaderMapFinalizeResults,0> > & CompiledShaderMaps, float TimeBudget) Line 1766	C++
UE4Editor-Engine-Win64-Debug.dll!FShaderCompilingManager::ProcessAsyncResults(bool bLimitExecutionTime, bool bBlockOnGlobalShaderCompletion) Line 2369	C++
UE4Editor-Engine-Win64-Debug.dll!FCanvas::Construct() Line 271	C++
UE4Editor-Engine-Win64-Debug.dll!FCanvas::FCanvas(FRenderTarget * InRenderTarget, FHitProxyConsumer * InHitProxyConsumer, float InRealTime, float InWorldTime, float InWorldDeltaTime, ERHIFeatureLevel::Type InFeatureLevel) Line 260	C++
UE4Editor-GraphEditor-Win64-Debug.dll!FPreviewElement::DrawRenderThread(FRHICommandListImmediate & RHICmdList, const void * InWindowBackBuffer) Line 239	C++
UE4Editor-SlateRHIRenderer-Win64-Debug.dll!FSlateRHIRenderingPolicy::DrawElements(FRHICommandListImmediate & RHICmdList, FSlateBackBuffer & BackBuffer, const FMatrix & ViewProjectionMatrix, const TArray<FSlateRenderBatch,FDefaultAllocator> & RenderBatches, bool bAllowSwitchVerticalAxis) Line 707	C++
UE4Editor-SlateRHIRenderer-Win64-Debug.dll!FSlateRHIRenderer::DrawWindow_RenderThread(FRHICommandListImmediate & RHICmdList, FSlateRHIRenderer::FViewportInfo & ViewportInfo, FSlateWindowElementList & WindowElementList, bool bLockToVsync, bool bClear) Line 766	C++
UE4Editor-SlateRHIRenderer-Win64-Debug.dll!FSlateRHIRenderer::DrawWindows_Private::__l35::<lambda>(FRHICommandListImmediate & RHICmdList) Line 1052	C++
UE4Editor-SlateRHIRenderer-Win64-Debug.dll!TGraphTask<TEnqueueUniqueRenderCommandType<`FSlateRHIRenderer::DrawWindows_Private'::`35'::SlateDrawWindowsCommandName,void <lambda>(FRHICommandListImmediate &) > >::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 885	C++
UE4Editor-Core-Win64-Debug.dll!FNamedTaskThread::ProcessTasksNamedThread(int QueueIndex, bool bAllowStall) Line 954	C++
UE4Editor-Core-Win64-Debug.dll!FNamedTaskThread::ProcessTasksUntilQuit(int QueueIndex) Line 701	C++
UE4Editor-Core-Win64-Debug.dll!FTaskGraphImplementation::ProcessThreadUntilRequestReturn(ENamedThreads::Type CurrentThread) Line 1759	C++
UE4Editor-RenderCore-Win64-Debug.dll!RenderingThreadMain(FEvent * TaskGraphBoundSyncEvent) Line 327	C++
UE4Editor-RenderCore-Win64-Debug.dll!FRenderingThread::Run() Line 461	C++
UE4Editor-Core-Win64-Debug.dll!FRunnableThreadWin::Run() Line 74	C++
UE4Editor-Core-Win64-Debug.dll!FRunnableThreadWin::GuardedRun() Line 25	C++
UE4Editor-Core-Win64-Debug.dll!FRunnableThreadWin::_ThreadProc(void * pThis) Line 78	C++
[External Code]	

The assert is in this assert in Shader.cpp

FShaderResource* FShaderResource::FindShaderResourceById(const FShaderResourceId& Id)
{
	check(IsInGameThread());
	FShaderResource* Result = ShaderResourceIdMap.FindRef(Id);
	return Result;
}

The current thread is ActualRenderThread IIRC.

Seems to be caused by this commit:

https://github.com/EpicGames/UnrealEngine/commit/ce06047164aceb6d4f7a6a481419f26a7a0c60b5