Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

TextMesh Pro WebGL & .Net 4.6

Discussion in 'Unity UI & TextMesh Pro' started by Sgrueling, Nov 15, 2017.

  1. Sgrueling

    Sgrueling

    Joined:
    Nov 7, 2016
    Posts:
    10
    Hello,

    I just would request an update regarding the situation with TextMeshPro, WebGL and .net 4.6.
    Currently it throws this exception when I build a WebGL Version.

    Code (CSharp):
    1. Rethrow as TypeInitializationException: The type initializer for 'System.Globalization.CharUnicodeInfo' threw an exception.
    It's reported in this Issue: https://issuetracker.unity3d.com/is...doperationexception-on-webgl-with-net-4-dot-6

    Last post regarding this was: https://forum.unity.com/threads/tex...ed-text-rendering.248636/page-40#post-3162858

    Is there anyway to work around this? Is there a fix on the way?
    Any update?

    Regards,
    Shane
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,213
    In what version of Unity are you getting this error?

    As you may already know, this issue is exposed by TMP but not specific to it. I thought it had been addressed but let me see if I can track down those who would be looking into this.
     
  3. Sgrueling

    Sgrueling

    Joined:
    Nov 7, 2016
    Posts:
    10
    Tried it today in 2017.2.0p1 but i have it since it's .net 4.6 is available.

    Thanks already for the quick answer! :)
     
  4. Sgrueling

    Sgrueling

    Joined:
    Nov 7, 2016
    Posts:
    10
    *bump*

    Found anyone? ;)
     
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,213
    The team handling .Net 4.6 is aware of the issue but no ETA on a fix yet.
     
  6. Sgrueling

    Sgrueling

    Joined:
    Nov 7, 2016
    Posts:
    10
    Thanks!
     
  7. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    504
    Running into this in 2018.1. Was there any final resolution or workaround here?
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,111
    @Claytonious

    Are you enabling embedded resources for WebGL? This issue only happens when IL2CPP tries to load the embedded resources in the mscorlib.dll assembly on WebGL with the .NET 4.x scripting runtime. By default, embedded resources are not enabled for WebGL (to save build size).

    So if you don't need embedded resources and have them enabled, I would recommend disabling them. That should work around this issue.
     
  9. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    504
    No, we are NOT building with embedded resources. This is a fairly "vanilla" setup. Just having a TextMeshPro input field in WebGL with net standard 2.0 scripting seems to cause this exception.

    Should I try building WITH embedded resources? (Sounds like you are saying the opposite, but I want to make sure).
     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,111
    Yes, I'm saying you should not build with embedded resources. I'm surprised to see this happening without embedded resources enabled. I may not fully understand your situation. In any case, we have a fix on the way for this issue. It should be in a 2018.1 patch release soon.
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,111
    I've thoroughly confused this issue, sorry about that. I thought this was a different problem - I did not go back and look at the original bug report.

    So, to correct this, you should build for WebGL with embedded resources enabled. Please ignore my previous comments, they were about a different issue.
     
    Claytonious likes this.
  12. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    504
    Got it. Will let you know how it goes. Thank you!
     
  13. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    504
    Unfortunately, even building with embedded resources did not fix the problem. Setting the text on any TextMeshProInputField in a WebGL build still leads to:

    Code (CSharp):
    1. System.TypeInitializationException: The type initializer for 'System.Globalization.CharUnicodeInfo' threw an exception. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
    2.   at System.Globalization.GlobalizationAssembly.GetGlobalizationResourceBytePtr (System.Reflection.Assembly assembly, System.String tableName) [0x00000] in <00000000000000000000000000000000>:0
    3.   at System.Globalization.CharUnicodeInfo.InitTable () [0x00000] in <00000000000000000000000000000000>:0
    4.   at System.Globalization.CharUnicodeInfo..cctor () [0x00000] in <00000000000000000000000000000000>:0
    5.   at System.Char.IsWhiteSpace (System.Char c) [0x00000] in <00000000000000000000000000000000>:0
    6.   at TMPro.TextMeshProUGUI.SetArraySizes (System.Int32[] chars) [0x00000] in <00000000000000000000000000000000>:0
    7.   at TMPro.TMP_Text.ParseInputText () [0x00000] in <00000000000000000000000000000000>:0
    8.   at TMPro.TMP_Text.GetPreferredHeight () [0x00000] in <00000000000000000000000000000000>:0
    9.   at TMPro.TMP_Text.get_preferredHeight () [0x00000] in <00000000000000000000000000000000>:0
    10.   at TMPro.TMP_InputField.AdjustTextPositionRelativeToViewport (System.Single relativePosition) [0x00000] in <00000000000000000000000000000000>:0
    11.   at TMPro.TMP_InputField.set_text (System.String value) [0x00000] in <00000000000000000000000000000000>:0
    I built with embedded resources by doing this:

    Code (CSharp):
    1.     public class WebGlBuilder : IProcessSceneWithReport
    2.     {
    3.         private static bool _hasSetup;
    4.         public int callbackOrder => 0;
    5.        
    6.         public void OnProcessScene(Scene scene, BuildReport report)
    7.         {
    8.             if (!_hasSetup)
    9.             {
    10.                 _hasSetup = true;
    11. #pragma warning disable 0618
    12.                 PlayerSettings.SetPropertyBool("useEmbeddedResources", true, BuildTargetGroup.WebGL);
    13. #pragma warning restore 0618
    14.             }          
    15.         }
    16.     }
    17.  
     
  14. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    504
    I spoke too soon! Apparently, setting the flag in an implementation of IProcessSceneWithReport had no effect. By just manually executing this from a menu item and then saving the project, THEN rebuilding, this did, in fact, fix the problem.

    Thank you for your help @JoshPeterson. Needless to say, this will be a roadblock for other users but it sounds like you're fixing it "out of the box" for a future release already.
     
  15. Gigacee

    Gigacee

    Joined:
    Mar 4, 2015
    Posts:
    5
    Same error in Unity 2018.1.0f2 and .Net 4.x. I can't use TextMeshProUGUI on WebGL because of this error.

    Code (CSharp):
    1. InvalidOperationException: Operation is not valid due to the current state of the object.
    2. at System.Globalization.GlobalizationAssembly.GetGlobalizationResourceBytePtr (System.Reflection.Assembly assembly, System.String tableName) [0x00000] in <00000000000000000000000000000000>:0
    3. Rethrow as TypeInitializationException: The type initializer for 'System.Globalization.CharUnicodeInfo' threw an exception.
    4.  
    5. (Filename: currently not available on il2cpp Line: -1)
    Incomprehensibly, TextMeshPro (not in Canvas) is work correctly.
    And TextMeshProUGUI with only alphanumeric characters is work correctly too.
    I use TextMeshProUGUI and Japanese in my Game and some of them break.
     
  16. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    504
    Did you build with embedded resources?
     
  17. Gigacee

    Gigacee

    Joined:
    Mar 4, 2015
    Posts:
    5
    Sorry, I didn't build with embedded resources enabled because I didn't know how to do it.

    I examined again today and I could do it by following script:

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. public class WebGLEditorScript
    4. {
    5.     [MenuItem("Tools/WebGL/Enable Embedded Resources")]
    6.     public static void EnableEmbeddedResources()
    7.     {
    8.         PlayerSettings.WebGL.useEmbeddedResources = true;
    9.     }
    10. }
    11.  
    And then, TextMeshProUGUI was working fine in .Net 4.x. Thank you!
     
    JoshPeterson and Stephan_B like this.
  18. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,213