We noticed some inconsistencies when toggling static switches of materials in the Material Constant Editor after updating to 5.6. The issue would manifest in the form of the preview material disappearing or having the wrong branch compiled.
I tracked it down to uninitialized values in the PreshaderBuffer. The following one line in MaterialUniformExpressions.cpp fixes the issue. Sharing it here as I haven’t seen it reported elsewhere. The attached images show the buffer contents when correct and when they are uninitialized.
// Copy the value to the target position
CopyValueToUniformBuffer(ParameterShaderValue, (float*)BufferCursor, Evaluation.BufferOffset);
}
// Dump preshader results into buffer.
float* const PreshaderBuffer = (float*)BufferCursor;
+ FMemory::Memzero(PreshaderBuffer, UniformPreshaderBufferSize * 4 * sizeof(float));
FPreshaderStack PreshaderStack;
FPreshaderDataContext PreshaderBaseContext(UniformPreshaderData);
for (const FMaterialUniformPreshaderHeader& Preshader : UniformPreshaders)
{
FPreshaderDataContext PreshaderContext(PreshaderBaseContext, Preshader.OpcodeOffset, Preshader.OpcodeSize);
const FPreshaderValue Result = EvaluatePreshader(this, MaterialRenderContext, PreshaderStack, PreshaderContext);