BUG-2225: This should fix an immediate issue, NullReferenceException, where the color is null.

This commit is contained in:
Krom, Robertus 2017-06-21 08:20:40 +02:00
commit d9c56ff2a9
2 changed files with 5 additions and 5 deletions

View file

@ -132,7 +132,7 @@ namespace Greenshot.Drawing.Fields
public object GetFieldValue(IFieldType fieldType)
{
return GetField(fieldType).Value;
return GetField(fieldType)?.Value;
}
#region convenience methods to save us some casts outside
@ -166,9 +166,9 @@ namespace Greenshot.Drawing.Fields
return Convert.ToBoolean(GetFieldValue(fieldType));
}
public Color GetFieldValueAsColor(IFieldType fieldType)
public Color GetFieldValueAsColor(IFieldType fieldType, Color defaultColor = default(Color))
{
return (Color)GetFieldValue(fieldType);
return (Color)(GetFieldValue(fieldType) ?? defaultColor);
}
#endregion

View file

@ -62,8 +62,8 @@ namespace Greenshot.Drawing {
public override void Draw(Graphics graphics, RenderMode rm) {
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR, Color.Red);
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR, Color.Transparent);
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);