Change FontReference to reference type
FontReference is mutating itself by storing the cached font for later reuse, but this is not working as intended because FontReference is returned as a value type in UIControls so the cached font is actually stored in a copy of the FontReference and not in the original property.
This commit is contained in:
@@ -7,7 +7,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Font reference that defines the font asset and font size to use.
|
||||
/// </summary>
|
||||
public struct FontReference
|
||||
public class FontReference
|
||||
{
|
||||
[NoSerialize]
|
||||
private FontAsset _font;
|
||||
@@ -96,9 +96,9 @@ namespace FlaxEngine
|
||||
/// <c>true</c> if the specified <see cref="FontReference" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(ref FontReference other)
|
||||
public bool Equals(FontReference other)
|
||||
{
|
||||
return _font == other._font && _size == other._size;
|
||||
return !(other is null) && _font == other._font && _size == other._size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -109,7 +109,9 @@ namespace FlaxEngine
|
||||
/// <returns>True if font references are equal, otherwise false.</returns>
|
||||
public static bool operator ==(FontReference lhs, FontReference rhs)
|
||||
{
|
||||
return lhs.Equals(ref rhs);
|
||||
if (lhs is null)
|
||||
return rhs is null;
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,7 +122,9 @@ namespace FlaxEngine
|
||||
/// <returns>True if font references are not equal, otherwise false.</returns>
|
||||
public static bool operator !=(FontReference lhs, FontReference rhs)
|
||||
{
|
||||
return !lhs.Equals(ref rhs);
|
||||
if (lhs is null)
|
||||
return !(rhs is null);
|
||||
return !lhs.Equals(rhs);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -129,7 +133,7 @@ namespace FlaxEngine
|
||||
if (!(other is FontReference))
|
||||
return false;
|
||||
var fontReference = (FontReference)other;
|
||||
return Equals(ref fontReference);
|
||||
return Equals(fontReference);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -137,7 +141,7 @@ namespace FlaxEngine
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hashCode = _font.GetHashCode();
|
||||
int hashCode = _font ? _font.GetHashCode() : 0;
|
||||
hashCode = (hashCode * 397) ^ _size;
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user