Skip to content

Commit

Permalink
Add better protection against empty Layer property when computing Mat…
Browse files Browse the repository at this point in the history
…erialComposition
  • Loading branch information
IsakNaslundBh committed Mar 10, 2023
1 parent fe3f8c4 commit 7558747
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Physical_Engine/Query/MaterialComposition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,17 @@ private static MaterialComposition MaterialComposition(this Construction prop)
return null;
}

if (prop.Layers.IsNullOrEmpty()) //.IsNullOrEmpty raises it's own error
if (prop.Layers == null) //.IsNullOrEmpty raises it's own error
{
Base.Compute.RecordError("Cannote evaluate MaterialComposition because the layers are null.");
return null;
}

if (prop.Layers.Count == 0)
{
Base.Compute.RecordWarning($"Construction {(string.IsNullOrEmpty(prop.Name) ? "NoName" : prop.Name)} does not conatin any layers. An empty MaterialComposition is returned in its place.");
return new MaterialComposition(new List<Material>(), new List<double>());
}

if (prop.Layers.All(x => x.Material == null))
{
Expand Down
5 changes: 5 additions & 0 deletions Physical_Engine/Query/VolumetricMaterialTakeoff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public static VolumetricMaterialTakeoff IVolumetricMaterialTakeoff(this IOpening

private static VolumetricMaterialTakeoff TakeOff(double area, IConstruction construction)
{
MaterialComposition comp = construction.IMaterialComposition();
if (comp == null)
return null;
if(comp.Materials.Count == 0)
return new VolumetricMaterialTakeoff(new List<Material>(), new List<double>());
return Matter.Create.VolumetricMaterialTakeoff(construction.IMaterialComposition(), construction.IThickness() * area);
}

Expand Down

0 comments on commit 7558747

Please sign in to comment.