From 79b03f6b5cb9c747e0faff634be552644cb6cfee Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 9 Jun 2021 11:11:32 +0200 Subject: [PATCH] Fix cached font usage to use proper unmanaged object validation check (not only managed object ref) #546 --- Source/Engine/Render2D/FontReference.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Render2D/FontReference.cs b/Source/Engine/Render2D/FontReference.cs index 0d725a5a6..98bd0d092 100644 --- a/Source/Engine/Render2D/FontReference.cs +++ b/Source/Engine/Render2D/FontReference.cs @@ -36,8 +36,16 @@ namespace FlaxEngine /// The font. public FontReference(Font font) { - _font = font?.Asset; - _size = font?.Size ?? 30; + if (font) + { + _font = font.Asset; + _size = font.Size; + } + else + { + _font = null; + _size = 30; + } _cachedFont = font; } @@ -85,7 +93,11 @@ namespace FlaxEngine /// Th font or null if descriptor is invalid. public Font GetFont() { - return _cachedFont ?? (_cachedFont = _font?.CreateFont(_size)); + if (_cachedFont) + return _cachedFont; + if (_font) + _cachedFont = _font.CreateFont(_size); + return _cachedFont; } ///