Search Unity

Crash On CanBindTo SpriteAtlas request invoke. when first running apps use download assetbundle

Discussion in '2D' started by changdocs, May 9, 2019.

  1. changdocs

    changdocs

    Joined:
    Jan 21, 2019
    Posts:
    1
    Hello unity users.
    It's my first time write to unity forum

    I Need HELP!!

    here is parts of my project's crash report..

    Thread 0 Crashed:
    0 MYPROJECT 0x0000000102eb149c Sprite::GetRenderDataKey() const (in MYPROJECT) + 0
    1 MYPROJECT 0x0000000102dfd050 SpriteAtlas::CanBindTo(Sprite const*) const (in MYPROJECT) + 36
    2 MYPROJECT 0x000000010306a9d8 SpriteAtlas_CUSTOM_CanBindTo(Il2CppObject*, Il2CppObject*) (in MYPROJECT) + 80
    3 MYPROJECT 0x0000000104d2ec14 Image_RebuildImage_mB4AA47E0011889F0491C290A025B1FDC53F53743 (in MYPROJECT) + 280
    4 MYPROJECT 0x000000010427ed78 Action_1_Invoke_mB86FC1B303E77C41ED0E94FC3592A9CF8DA571D5_gshared (in MYPROJECT) + 792
    5 MYPROJECT 0x00000001029f3f8c RuntimeInvoker_FalseVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017_RuntimeObject(void (*)(), MethodInfo const*, void*, void**) (in MYPROJECT) + 20
    6 MYPROJECT 0x00000001036cf2b4 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) (in MYPROJECT) + 108
    7 MYPROJECT 0x0000000103019f8c scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) (in MYPROJECT) + 100
    8 MYPROJECT 0x00000001030227e4 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) (in MYPROJECT) + 60
    9 MYPROJECT 0x0000000102dfda94 SpriteAtlasManager::Register(PPtr<SpriteAtlas>) (in MYPROJECT) + 412
    10 MYPROJECT 0x000000010415bb54 AssetBundleHelper_OnAtlasRequested_m5DB84044CE68AE1D30678038D377D8512828A4E2 (in MYPROJECT) + 1012
    11 MYPROJECT 0x0000000104cc21b4 SpriteAtlasManager_RequestAtlas_m792F61C44C634D9E8F1E15401C8CECB7A12F5DDE (in MYPROJECT) + 304

    AssetBundleHelper is my project's class that handling SpriteAtlas requested.

    I Made project use SpriteAtlas using from downloaded assetbundles.

    But, on device, Install app and first launch time running normaly. for a while. after move sevaral scenes suddenly occured crash what you look upper crash stacks.

    After crash. When I re launch app. It's OK all the time............. that makes me crazy!!!


    I can't found similar case by googling.


    Anyone has same experience with my case?.. Somebody help me....
     
    lenchez-mrg likes this.
  2. MaydayWorks

    MaydayWorks

    Joined:
    Aug 18, 2014
    Posts:
    6
    I occured the same problem...
     
  3. leuconoe

    leuconoe

    Joined:
    Oct 14, 2014
    Posts:
    15
    Bump,
    I suddenly had a problem.
    2018.3.14f1
     
  4. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Bumping as I'm running into the same. Does anyone have a workaround for this?
     
  5. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    @changdocs
    @MaydayWorks
    @leuconoe
    @joe_nk
    Sorry for the delay in response. We are working on a fix for this issue. Will update this thread as soon as we have a fix published. Thanks for posting.
     
    joe_nk likes this.
  6. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Thanks, I traced the crash to a null reference in Image.RebuildImage, see here
     
  7. Taylor_G

    Taylor_G

    Joined:
    Jan 23, 2017
    Posts:
    1
    @Venkify any chance there's an issue tracker link you could share, or some other way we can get notified of progress on this issue?
     
  8. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    Sorry for the delay in posting an Update. Here are the versions with the fixes :

    2020.2 : > 2020.2.0a21
    2020.1 : > 2020.1.4f1
    2019.4 : > 2019.4.9f1

    Thanks.
     
    Taylor_G likes this.
  9. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    391
    I met this issue in 2017.4.40f1.
    Based on the answer of @joe_nk, I fix it using the following code:
    Code (CSharp):
    1. public class SpriteAtlasLoader : MonoBehaviour
    2. {
    3.     private List<Image> myTrackedImages;
    4.  
    5.     private void Awake()
    6.     {
    7.         var field = typeof(Image).GetField("m_TrackedTexturelessImages",
    8.             BindingFlags.NonPublic | BindingFlags.Static);
    9.         myTrackedImages = (List<Image>)field.GetValue(null);
    10.  
    11.         SpriteAtlasManager.atlasRequested += OnAtlasRequested;
    12.     }
    13.  
    14.     private void OnDestroy()
    15.     {
    16.         SpriteAtlasManager.atlasRequested -= OnAtlasRequested;
    17.     }
    18.  
    19.     private SpriteAtlas Load(string tag)
    20.     {
    21.         // Load SpriteAtlas and return it
    22.     }
    23.  
    24.     private void OnAtlasRequested(string tag, Action<SpriteAtlas> action)
    25.     {
    26.         var atlas = Load(tag);
    27.         ClearInvalidImages();
    28.  
    29.         action(atlas);
    30.     }
    31.  
    32.     private void ClearInvalidImages()
    33.     {
    34.         for (int i = myTrackedImages.Count - 1; i >= 0; --i)
    35.         {
    36.             var image = myTrackedImages[i];
    37.             if (image.overrideSprite == null)
    38.                 myTrackedImages.RemoveAt(i);
    39.         }
    40.     }
    41. }
     
    joe_nk likes this.
  10. TheJimz

    TheJimz

    Joined:
    Jun 26, 2015
    Posts:
    50
    NOT fixed in Unity 2020.3.8f1. The issue began for us once we started using variant atlases.
     
  11. Ed-Marty

    Ed-Marty

    Joined:
    Jul 16, 2015
    Posts:
    15
    Also not fixed in 2019.4.17f1. We have plans to update to a later version soon. Hopefully it will be fixed there. The stack trace is slightly different:

     
  12. lenchez-mrg

    lenchez-mrg

    Joined:
    Dec 13, 2018
    Posts:
    5
    We've got the same issue with Unity 2021.3.5f1

    When a late binding atlas is loaded and TilemapRenderer's delegates get invoked the game crashes with a null pointer dereference in native code:

    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x100
    Cause: null pointer dereference


    This behaviour appears both in Android build and in the Editor (the editor itself crashes). Naturally, to reproduce it in editor you have to set Sprite Packer Mode to "Always Enabled" in Edit - Project Settings - Editor.

    When I create a simple Tilemap from scratch - it doesn't crash the game. However the game does crash when our actual assets are loaded. Maybe it has something to do with those assets being created in earlier versions of Unity. I'm still unable to pinpoint a particular cause.

    The call stack of the crash is the same in Android build and Mac OS Editor:

    #0 0x00000103252870 in Sprite::GetRenderDataKey() const

    #1 0x00000103ddb1f8 in TilemapRenderer::OnSpriteAtlasRegistered(SpriteAtlas*)

    #2 0x00000102db01b4 in TilemapRenderer_CUSTOM_OnSpriteAtlasRegistered(ScriptingBackendNativeObjectPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)

    #3 0x000006f8533c0c in (wrapper managed-to-native) UnityEngine.Tilemaps.TilemapRenderer:OnSpriteAtlasRegistered (UnityEngine.Tilemaps.TilemapRenderer,UnityEngine.U2D.SpriteAtlas) [{0x3d3e24880} + 0xcc] (0x6f8533b40 0x6f8533ca0) [0x144502a80 - Unity Child Domain]

    #4 0x000006f83a0904 in (wrapper delegate-invoke) System.Action`1<T_REF>:invoke_void_T (T_REF) [{0x600001d1ccc0} + 0x224] (0x6f83a06e0 0x6f83a0974) [0x144502a80 - Unity Child Domain]

    #5 0x000006f8533b04 in UnityEngine.U2D.SpriteAtlasManager:PostRegisteredAtlas (UnityEngine.U2D.SpriteAtlas) [{0x4308eba48} + 0x9c] [/Users/bokken/buildslave/unity/build/Runtime/2D/SpriteAtlas/ScriptBindings/SpriteAtlas.bindings.cs :: 31u] (0x6f8533a68 0x6f8533b40) [0x144502a80 - Unity Child Domain]

    #6 0x000006f5e97930 in (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr) [{0x430871a10} + 0xc0] (0x6f5e97870 0x6f5e979f8) [0x144502a80 - Unity Child Domain]

    #7 0x0000016401190c in mono_jit_runtime_invoke

    #8 0x000001641976a8 in do_runtime_invoke

    #9 0x000001641975c8 in mono_runtime_invoke

    #10 0x000001037a3a48 in scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)

    #11 0x0000010379ebb8 in ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)

    #12 0x000001030a72b4 in SpriteAtlasManager::Register(PPtr<SpriteAtlas>)

    #13 0x00000102c451a8 in SpriteAtlasManager_CUSTOM_Register(ScriptingBackendNativeObjectPtrOpaque*)

    #14 0x000006f8533984 in (wrapper managed-to-native) UnityEngine.U2D.SpriteAtlasManager:Register (UnityEngine.U2D.SpriteAtlas) [{0x2ec0ea318} + 0xa4] (0x6f85338e0 0x6f8533a18) [0x144502a80 - Unity Child Domain]

    --- here goes our code providing a loaded atlas to SpriteAtlasManager ---
    #15 0x000006f8533728 in game.AssetLoading:CompleteAtlasRequest (string,UnityEngine.U2D.SpriteAtlas,System.Action`1<UnityEngine.U2D.SpriteAtlas>)
     
  13. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    Could you kindly report a bug with a simple repro project ? Also do you observe this issue only with TilemapRenderer's delegates ?
    Thanks.
     
  14. lenchez-mrg

    lenchez-mrg

    Joined:
    Dec 13, 2018
    Posts:
    5
    I observe this issue only with TilemapRenderer's delegates. I'm still unable to pinpoint the issue to make a simple repro project. Seems like it has something to do with our assets made in older Unity versions.
     
  15. lenchez-mrg

    lenchez-mrg

    Joined:
    Dec 13, 2018
    Posts:
    5
    Okay, seems like I've found the source of this problem. In my case the crash was caused by Tilemap having Tiles with missing/invalid Sprites. Hard to tell where they came from originally, probably some sprites referenced in Tiles were deleted from the project at some point.

    I've iterated over all the prefabs in the project and analysed their Tilemaps like this:

    Code (CSharp):
    1.   static void TilemapForeachTile(UnityEngine.Tilemaps.Tilemap tilemap, TileAction cb = null)
    2.   {
    3.     var bounds = tilemap.cellBounds;
    4.     for(int x = bounds.min.x; x <= bounds.max.x; x++)
    5.     {
    6.       for(int y = bounds.min.y; y <= bounds.max.y; y++)
    7.       {
    8.         for(int z = bounds.min.z; z <= bounds.max.z; z++)
    9.         {
    10.           var coord = new Vector3Int(x, y, z);
    11.           var tile = tilemap.GetTile<UnityEngine.Tilemaps.Tile>(coord);
    12.           if(tile == null)
    13.             continue;
    14.  
    15.           var sprite = tile.sprite;
    16.           var sprite_path = AssetDatabase.GetAssetPath(sprite);
    17.           var sprite_guid = AssetDatabase.GUIDFromAssetPath(sprite_path);
    18.        
    19.           //Here, if sprite_guid is all zeroes - it means the Tile references a missing/corrupted Sprite
    20.           //Such tiles should be removed from the Tilemap
    21.         }
    22.       }
    23.     }
    24.   }
    25.  
    The game no longer crashes after I've removed all such corrupted Tiles from all the Tilemaps.

    Probably there were no crashes in Unity 2018 because TilemapRenderers did not have their own SpriteAtlasManager.atlasRegistered delegates back then. So there was no access to a missing/corrupted Sprite after SpriteAtlas has been loaded.