There is (again) an error in the next line where the if-condition should  read:
```if (!MeshLayerMapper::LayerMapping(*mesh_layer, *rasters[i], 0, 0, replacement_value)) {...} ```
i.e. ```replacement_value``` is used there.

Explanation: If the raster for a subsurface layer doesn't cover the whole model area, the nodes get a default elevation (```_invalid_value```) to signify that these nodes should be snapped to the layer above. (This allows for cropping layers).
For the surface layer there is *no* layer above so you need a "default" value (```noDataReplacementValue```) in case the raster doesn't cover the whole area.