Since the both the
check(OutUniformExpressionCache.UniformBuffer->GetLayout() == UniformBufferStruct.GetLayout());
RHIUpdateUniformBuffer(OutUniformExpressionCache.UniformBuffer, TempBuffer);
functions cause the engine to crash I’m assuming the (IsValidRef(OutUniformExpressionCache.UniformBuffer)) If check is returning TRUE when it should be returning FALSE. But forcing it down the FALSE (else) statement so that only
OutUniformExpressionCache.UniformBuffer = RHICreateUniformBuffer(TempBuffer, UniformBufferStruct.GetLayout(), UniformBuffer_MultiFrame);
is called, the crash does not occur. My edited version of the function is below:
void FMaterialRenderProxy::EvaluateUniformExpressions(FUniformExpressionCache& OutUniformExpressionCache, const FMaterialRenderContext& Context, FRHICommandList* CommandListIfLocalMode) const
{
check(IsInParallelRenderingThread());
SCOPE_CYCLE_COUNTER(STAT_CacheUniformExpressions);
// Retrieve the material's uniform expression set.
const FUniformExpressionSet& UniformExpressionSet = Context.Material.GetRenderingThreadShaderMap()->GetUniformExpressionSet();
OutUniformExpressionCache.CachedUniformExpressionShaderMap = Context.Material.GetRenderingThreadShaderMap();
const FShaderParametersMetadata& UniformBufferStruct = UniformExpressionSet.GetUniformBufferStruct();
FMemMark Mark(FMemStack::Get());
void* TempBuffer = FMemStack::Get().PushBytes(UniformBufferStruct.GetSize(), SHADER_PARAMETER_STRUCT_ALIGNMENT);
UniformExpressionSet.FillUniformBuffer(Context, TempBuffer);
if (CommandListIfLocalMode)
{
OutUniformExpressionCache.LocalUniformBuffer = CommandListIfLocalMode->BuildLocalUniformBuffer(TempBuffer, UniformBufferStruct.GetSize(), UniformBufferStruct.GetLayout());
check(OutUniformExpressionCache.LocalUniformBuffer.IsValid());
}
else
{
OutUniformExpressionCache.UniformBuffer = RHICreateUniformBuffer(TempBuffer, UniformBufferStruct.GetLayout(), UniformBuffer_MultiFrame);
}
OutUniformExpressionCache.ParameterCollections = UniformExpressionSet.ParameterCollections;
OutUniformExpressionCache.bUpToDate = true;
}
With this edit a recompile of the editor / engine the crash does not occur.