Making masked or two sided material crashes editor because of my custom render pass. How to fix it?

I made my own render pass by modifying engine. But editor always crash when I make masked or two sided material.

This is my FMeshMaterialShader’s ShouldCompilePermutation()



static bool ShouldCompilePermutation(const FMeshMaterialShaderPermutationParameters& Parameters)
{
    return Parameters.MaterialParameters.bIsSpecialEngineMaterial
      || !Parameters.MaterialParameters.bWritesEveryPixel
      || Parameters.MaterialParameters.bMaterialMayModifyMeshPosition;
}


and condition in AddMeshBatch()



{
   const FMaterialRenderProxy* MaterialRenderProxy = MeshBatch.MaterialRenderProxy;
   const FMaterial* Material = &MaterialRenderProxy->GetMaterialWithFallback(FeatureLevel, MaterialRenderProxy);
   const EBlendMode BlendMode = Material->GetBlendMode();
   const bool bIsNotTranslucent = BlendMode == BLEND_Opaque || BlendMode == BLEND_Masked;

   if (bIsNotTranslucent
      && ShouldIncludeDomainInMeshPass(Material->GetMaterialDomain())
      && ShouldIncludeMaterialInDefaultOpaquePass(*Material))
   {
      if (Material->WritesEveryPixel()
         && !Material->IsTwoSided()
         && !Material->MaterialModifiesMeshPosition_RenderThread())
      {
         MaterialRenderProxy = UMaterial::GetDefaultMaterial(MD_Surface)->GetRenderProxy();
         Material = MaterialRenderProxy->GetMaterial(FeatureLevel);
      }

   check(Material && MaterialRenderProxy);

   Process(MeshBatch, BatchElementMask, StaticMeshId, PrimitiveSceneProxy, *MaterialRenderProxy, *Material, MeshFillMode, MeshCullMode);
}
}


I dug some engine code, but most of them are same. Any Ideas to fix this?

Also, just rendering opaque material doesn’t crash.