Search Issue Tracker

Won't Fix

Votes

0

Found in

2021.3.10f1

2022.1.17f1

2022.2.0b8

2023.1.0a10

Issue ID

UUM-15170

Regression

Yes

Crash on FontEngine_CUSTOM_GetFaceInfo_Internal when entering Play mode

--

-

Reproduction steps:

# Open the attached project “FontCrash.zip“
# Enter Play mode

Expected result: Play mode is entered successfully
Actual result: the Editor crashes

Reproducible with: 2021.3.10f1, 2022.1.17f1, 2022.2.0b8, 2023.1.0a10
Could not test with: 2020.3.39f1 - due to errors in the Console when downgrading the project

Reproduced on: Windows 10 Pro

First few lines of the stack traces:
{{0x00007ff6c178a644 (Unity) FontEngine_CUSTOM_GetFaceInfo_Internal }}
{{0x0000023087551cf1 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.TextCore.LowLevel.FontEngine:GetFaceInfo_Internal (UnityEngine.TextCore.FaceInfo&) }}
{{0x0000023087551a9b (Mono JIT Code) UnityEngine.TextCore.LowLevel.FontEngine:GetFaceInfo () }}
{{0x000002308754dde3 (Mono JIT Code) [TMP_FontAsset.cs:464] TMPro.TMP_FontAsset:CreateFontAsset (UnityEngine.Font,int,int,UnityEngine.TextCore.LowLevel.GlyphRenderMode,int,int,TMPro.AtlasPopulationMode,bool) }}
{{0x000002308754ca93 (Mono JIT Code) [TMP_FontAsset.cs:434] TMPro.TMP_FontAsset:CreateFontAsset (UnityEngine.Font) }}

{{0x00007FFF57F7F039 (Unity) TextCore::FontEngine::GetFaceInfo }}
{{0x00007FFF56C9B439 (Unity) FontEngine_CUSTOM_GetFaceInfo_Internal }}
{{0x0000026EAC0644B1 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.TextCore.LowLevel.FontEngine:GetFaceInfo_Internal (UnityEngine.TextCore.FaceInfo&) }}
{{0x0000026EAC06425B (Mono JIT Code) UnityEngine.TextCore.LowLevel.FontEngine:GetFaceInfo () }}
{{0x0000026EAC060353 (Mono JIT Code) [C:\Users\AgnieteMargeviciute\Documents\Unity Projects\My project (1)\Library\PackageCache\com.unity.textmeshpro@3.0.6\Scripts\Runtime\TMP_FontAsset.cs:464] TMPro.TMP_FontAsset:CreateFontAsset (UnityEngine.Font,int,int,UnityEngine.TextCore.LowLevel.GlyphRenderMode,int,int,TMPro.AtlasPopulationMode,bool) 8}}

  1. Resolution Note:

    I had a chance to review the following case which is the result of the font's family and style name being in Chinese which is not handled correctly by FreeType. The family_name and style_name of the font face are null.

    I will find an appropriate way to handle such occurrences.

    Having said that, I had a chance to also review the user's implementation for which we can provide a much more efficient way of achieving the same result but with less memory overhead.

    In this case, the user is creating font assets from Font objects which results in unnecessary memory allocations, it is much more efficient to create font asset from either a file path or font family name or style names like shown in the example bellow:

    ///////// Two potential ways of creating new font assets at runtime \\\\\\\\\\\

    using UnityEngine;
    using UnityEngine.TextCore.LowLevel;
    using TMPro;

    public class DynamicFontAssetCreation : MonoBehaviour
    {
    public TMP_Text TextComponent;

    private TMP_FontAsset fontAsset;

    private void Awake()
    {
    // Returns the file path of all available system fonts.
    string[] systemFonts = Font.GetPathsToOSFonts();

    // Create new font asset from file path.
    fontAsset = TMP_FontAsset.CreateFontAsset(systemFonts[12], 0, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024);

    // Alternative implementation

    // Get system font names and styles
    string[] systemFontNames = FontEngine.GetSystemFontNames();

    // Get the font and style name for a particular array element.
    // Each string is formatted as follows: "familyName - StyleName".
    string[] fontFamilyAndStyleName = systemFontNames[17].Split(" - ");

    // Create new font asset from the font familyName and StyleName.
    fontAsset = TMP_FontAsset.CreateFontAsset(fontFamilyAndStyleName[0], fontFamilyAndStyleName[1]);

    TextComponent.font = fontAsset;
    }
    }

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.