Search Unity

TextMesh Pro Cannot initialize non-default texture with negative or zero width

Discussion in 'UGUI & TextMesh Pro' started by Munchy2007, Feb 6, 2023.

  1. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Getting this error when trying to build standalone with Unity 2023.1.0a24

    Full Error msg
    Code (CSharp):
    1. Cannot initialize non-default texture with negative or zero width.
    2. UnityEngine.Texture2D:Resize (int,int,UnityEngine.TextureFormat,bool)
    3. TMPro.TMP_FontAsset:ClearAtlasTextures (bool) (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_FontAsset.cs:2846)
    4. TMPro.TMP_FontAsset:ClearFontAssetDataInternal () (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_FontAsset.cs:2726)
    5. TMPro.TMP_PreBuildProcessor:OnPreprocessBuild (UnityEditor.Build.Reporting.BuildReport) (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Editor/TMP_PreBuildProcessor.cs:26)
    6. UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()
    Is there anything that can be done about this at the moment?
     
    Last edited: Feb 8, 2023
    Jomity likes this.
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Hi @Stephan_B ,

    This error seems to be specific to only one of my projects, as I'm able to successfully build another one (for Android), which also uses TMPro with Unity 2023.1.0a24.

    Can you point me in the right direction for what might be the cause and how I might resolve it?

    Thanks :)
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This issue is the result of some API change made by the graphic team where it is no longer possible to resize a texture to size 0. We now have to resize it to size 1.

    I believe that should be fixed in version 3.2.0-pre.4.
     
    yunzhencai, Kirsche and Munchy2007 like this.
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Thanks for getting back to me, good to hear a fix is in the pipeline.

    I can only see Version 3.0.6 in the package manager (I have Pre-release Packages enabled), how can I find out when 3.2.0-pre.4 is released and how would I get it, will it show in the Package Manager then?

    In the meantime is there any workaround other than reverting to an older Unity version, as any edits I make to the script are automatically reverted.
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You have to enable the option to see Preview Packages in Package Manager Settings. You can access those from the cog wheel in Package Manager itself or via the Project Settings - Advanced Settings.

    You can also add packages by name in the Package Manager as seen below

    upload_2023-2-9_15-59-45.png
     
  6. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    That's great, thanks :)
     
  7. MarvellousLunatic

    MarvellousLunatic

    Joined:
    May 1, 2020
    Posts:
    11
    Greetings,
    I updated Unity to the current alpha and faced the same Issue. I followed @Stephan_B advice and updated TMPro to the üre-release version. However, my font is no build incorrectly or not all.
    upload_2023-2-11_16-47-42.png
    upload_2023-2-11_16-41-55.png
    It's a custom font with dynamic characters.
    What can I do to fix this?
     
    Last edited: Feb 11, 2023
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Make sure that as per the Upgrade Note in the package description that you re-imported the TMP Essential Resources which contain the updated shaders.

    In addition, double check that the default material does have a reference to the font atlas texture.
     
  9. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    I had this OP's issue with 2023.1.0b12 and then the issue mentioned later with the font

    I seen no re-import, so I just removed it and re-added the package and re-imported Essentials

    Working now.

    Thanks
     
    akingdom and ragetli like this.
  10. farcry1124

    farcry1124

    Joined:
    May 10, 2013
    Posts:
    10
    This works. Thanks.
     
  11. leezak5555

    leezak5555

    Joined:
    Jan 16, 2020
    Posts:
    11
    Just to clarify to the unity begginners out there:
    When he said "Make sure that as per the Upgrade Note in the package description that you re-imported the TMP Essential Resources"
    He meant, do the following:
    1. Go to Window > TextMeshPro > Import TMP Essential Resources.
    2. If a pop-up window appears, click Import.
     
    Kujji, diydan, Benji3199 and 3 others like this.
  12. sHassan-XansrTech

    sHassan-XansrTech

    Joined:
    May 15, 2023
    Posts:
    16

    Great it solved my problem.
     
    andriej2301 likes this.
  13. IllTemperedTunas

    IllTemperedTunas

    Joined:
    Aug 31, 2012
    Posts:
    782
    Was able to solve this in my project by changing this setting to static
     
    Last edited: Jul 16, 2023
    Remaust, reyou, Kujji and 5 others like this.
  14. bentama

    bentama

    Joined:
    Jan 5, 2014
    Posts:
    5
    Had the same problem so I followed all the steps in this thread. Updated the package to 3.2.0-pre.4 and re-imported essentials and extras, but I get an error when I start play mode from the editor:

    InvalidCastException: Specified cast is not valid.
    TMPro.EditorUtilities.TMP_BaseEditorPanel.OnEnable () (at ./Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.4/Scripts/Editor/TMP_BaseEditorPanel.cs:259)
    TMPro.EditorUtilities.TMP_EditorPanelUI.OnEnable () (at ./Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.4/Scripts/Editor/TMP_EditorPanelUI.cs:19)

    This is the latest 2023 LTS and TextMeshPro doesn't seem to work at all.
     
  15. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    228
    I am having this same issue with 2023.1.3f1. It seems @leezak5555 suggestion works, but only for the first build. I need to keep doing the re-import every time I want to build.

    I tried upgrading to 4.0.0-pre.2 but it seems there has been a bunch of changes to the API and I would have to upgrade/troubleshoot many scripts to get up to date.

    Not sure why this isn't fixed in the release version of such a critical package.
     
  16. maddogedge

    maddogedge

    Joined:
    Apr 22, 2020
    Posts:
    5
    Hi, Any updates on when this will be fixed in a main release? I tried following 3.2.0-pre.4 installation route, but it caused more problems than it fixed
     
    Munchy2007 likes this.
  17. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Agreed, although I have managed to get this workaround implemented in a couple of my projects, it was a massive PITA fixing all the broken TMPro font asset references in prefabs.
     
  18. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    228
    Actually, I was able to fix this for good (I hope) using @IllTemperedTunas solution.
     
  19. ozdogano

    ozdogano

    Joined:
    Dec 7, 2017
    Posts:
    1
    hi guys i have founded the solution. @IllTemperedTunas page set dynamic and uncheck "clear dynamic data on build". when it is static, font look like arial. so it builds with this while it is dynamic.
     
  20. maddogedge

    maddogedge

    Joined:
    Apr 22, 2020
    Posts:
    5
    @ozdogano this worked for me thanks. Did you see a performance drop?
     
  21. Finn_Nua

    Finn_Nua

    Joined:
    Mar 27, 2023
    Posts:
    9
    thank you! this worked for me
     
    pedroareias16 likes this.
  22. ViktorMSc

    ViktorMSc

    Joined:
    May 28, 2022
    Posts:
    14
    I updated to com.unity.textmeshpro 3.2.0-pre.5 and it solved this issue for me
     
  23. Abdelfettah

    Abdelfettah

    Joined:
    May 5, 2019
    Posts:
    3
    Thank you man it work for me
     
  24. akingdom

    akingdom

    Joined:
    Mar 30, 2013
    Posts:
    15
    This worked for me with TextMeshPro 3.06, thanks.

     
  25. Dino000

    Dino000

    Joined:
    Dec 15, 2013
    Posts:
    5
    Thanks, this worked for me.
     
  26. pixelgm

    pixelgm

    Joined:
    Nov 21, 2021
    Posts:
    1
    Just downgrade to Unity Version to LTS and it'll be fixed.
     
  27. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    That's all well and good if you don't need features that are not available in the earlier version of the editor.
     
  28. yunzhencai

    yunzhencai

    Joined:
    Aug 1, 2022
    Posts:
    4
    I am using Unity 2023.1.5f1 and my problems are solved by using Textmeshpro version 3.2.0-pre.6!!
     
  29. ERCODER

    ERCODER

    Joined:
    Sep 30, 2022
    Posts:
    1
    my new text mesh pro texts are pink because of the shader does anyone know how to fix it
     
  30. reyou

    reyou

    Joined:
    Apr 30, 2015
    Posts:
    6