Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

1.4.0+ Serialized reference in UNITY_EDITOR definition causing black screen hard crash at runtime

Discussion in 'UGUI & TextMesh Pro' started by pushxtonotdie, Jun 20, 2019.

  1. pushxtonotdie

    pushxtonotdie

    Joined:
    Oct 21, 2010
    Posts:
    111
    Hi we're updating our code and migrating to using asmdefs instead of compiling our own dlls. It looks like we've got an issue with our builds having a black screen crash with the following issue:

    Code (csharp):
    1. A scripted object (probably TMPro.TMP_FontAsset?) has a different serialization layout when loading. (Read 2128 bytes but expected 10960 bytes) Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    Sure enough I look inside the TMP_FontAsset and that is exactly what I saw:


    Code (csharp):
    1.         #if UNITY_EDITOR
    2.         /// <summary>
    3.         /// Persistent reference to the source font file maintained in the editor.
    4.         /// </summary>
    5.         [SerializeField]
    6.         internal Font m_SourceFontFile_EditorRef;
    7.         #endif
    8.  
    What's weird about this is that we were not seeing this when we were compiling our dlls and linking to TMP. Perhaps we were linking against, and compiling, an editor-version of TMP into our build?

    This issue goes away if I reimport just TMPro or do a Reimport All. So it sounds like there may be some kind of bug with the compilation system or with Package Manager.

    It also goes away if I remove the #if in the package source.

    I currently don't have a project I can give you for a bug repro. I have a general idea of how to create one but I can't give you our current project. But this does seem like a bug, one that I'm also confused others are not encountering.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    A similar issue was reported a while back which is all related. The issue is related to Unity using the incorrect AsslemblyIndex which leads to this issue as it ends up using the Editor Assembly which has those extra fields.

    This was fixed but I do not believe it was backported. I am inquiring about this to get an update.

    A short term solution (for the previous case) for Desktop builds was to change Architecture Target which would cause Unity to rebuild these assembly indexes which would cure the issue. Basically forcing a refresh of the stale indexes. I presume doing the re-import ends up also forcing a refresh of those assembly indexes which also cure the issue.
     
  3. pushxtonotdie

    pushxtonotdie

    Joined:
    Oct 21, 2010
    Posts:
    111
    Interesting! I am currently attempting to determine how to swap architecture targets on the command line to fix this issue (since I can't do this manually on all our build farm), and also building out a repro project (even tho you said this is fixed).

    While I understand this seems like some kind of linking issue, I'm also a bit curious why #if-def-ing this serialized field isn't a bug? I thought that was a bad thing to do. Like...really bad. :D
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Having editor only serialized data is fine. That is provided it is handle correct on our end :)

    The reason this property is serialized only in the Editor is to have a persistent reference to the source font file as the sourceFontFile property is either set to null if the font asset is static or set to a reference of the font file if dynamic.