Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

The editor crash when I load scene from the asset bundle.

Discussion in '2018.2 Beta' started by watsonsong, Jun 28, 2018.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I am using the Ferr2D Terrain Tool to build my scene:
    https://forum.unity.com/threads/ferr2d-terrain-tool.204436/

    And I met a problem, when I load a scene contains the Ferr2D object from asset bundle, the editor and player will crash. But when I load it using the EditorApplicaition to load the scene, everything is OK.

    I am using the latest version of the Unity2018.2b10 with the .Net 4.x Equivalent and .Net Standard2.0. And the crash report is like below:
    Code (CSharp):
    1. 0x00007FFBC88B2375 (mono-2.0-bdwgc) [f:\dd\vctools\crt\vcruntime\src\string\amd64\memset.asm:129] memset
    2. 0x00007FFBC86B4FEB (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\boehm-gc.c:738] mono_gc_alloc_obj
    3. 0x00007FFBC8658B75 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:5506] mono_object_new_alloc_specific_checked
    4. 0x00007FFBC86590AA (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:5447] mono_object_new_specific_checked
    5. 0x00007FFBC865E4B3 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:5454] ves_icall_object_new_specific
    6. 0x00000000174717C8 (Mono JIT Code) (wrapper managed-to-native) object:__icall_wrapper_ves_icall_object_new_specific (intptr)
    7. 0x00000000174749AB (Mono JIT Code) [F:\Repositories\wind_game\Assets\Ferr\Common\2DT\Ferr2DT_Material.cs:34] Ferr2DT_Material:.ctor ()
    8. 0x0000000017474C18 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    9. 0x00007FFBC86CA4BB (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini-runtime.c:2809] mono_jit_runtime_invoke
    10. 0x00007FFBC8651AE2 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:2915] do_runtime_invoke
    11. 0x00007FFBC865AACF (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:2962] mono_runtime_invoke
    Is this a bug for the mono? I upload the crash dump file and submit a bug.
     

    Attached Files:

  2. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I test when I comment the constructor for the ferr2D, I met another crash:
    Code (CSharp):
    1. 0x00007FFBC862EAB1 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\metadata.c:5256] mono_metadata_class_equal
    2. 0x00007FFBC862C514 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\metadata.c:5091] _mono_metadata_generic_class_equal
    3. 0x00007FFBC864B80A (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\mono-hash.c:119] mono_g_hash_table_find_slot
    4. 0x00007FFBC864BC45 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\mono-hash.c:266] mono_g_hash_table_lookup
    5. 0x00007FFBC86982B9 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\reflection.c:476] mono_type_get_object_checked
    6. 0x00007FFBC86547A9 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:2135] mono_class_create_runtime_vtable
    7. 0x00007FFBC86553BD (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:1830] mono_class_vtable_full
    8. 0x00007FFBC8655303 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:1797] mono_class_vtable
    9. 0x00007FFBC8712066 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\method-to-ir.c:9986] mono_method_to_ir
    10. 0x00007FFBC86C0989 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini.c:3441] mini_method_compile
    11. 0x00007FFBC86C5541 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini.c:4177] mono_jit_compile_method_inner
    12. 0x00007FFBC86C9962 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini-runtime.c:2133] mono_jit_compile_method_with_opt
    13. 0x00007FFBC87A3BD6 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini-trampolines.c:716] common_call_trampoline
    14. 0x00007FFBC87A5BF4 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini-trampolines.c:848] mono_magic_trampoline
    15. 0x000000000E7803A3 (Mono JIT Code) <unknown class>.<unknown method>()
    16. 0x000000005946CE9B (Assembly-CSharp) Spine.Unity.SkeletonRenderer..ctor()
    17. 0x000000005946CAFB (Assembly-CSharp) Spine.Unity.SkeletonAnimation..ctor()
    18. 0x0000000059462578 (mscorlib) System.Object.runtime_invoke_void__this__()
    19. 0x00007FFBC86CA4BB (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini-runtime.c:2809] mono_jit_runtime_invoke
    20. 0x00007FFBC8651AE2 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:2915] do_runtime_invoke
    21. 0x00007FFBC865AACF (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:2962] mono_runtime_invoke
    This time it is the Spine.Unity.SkeletonRenderer, which is a useful 2D animation tool:
    esotericsoftware.com

    The problem seems like any constructor will crash when using the asset bundle mode.
     
  3. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I find the crash is because I use the AssetBundle.LoadFromStream from a custom stream, with a very simple crypt process.
    I load the asset bundle like this:
    Code (CSharp):
    1. var file = File.OpenRead(path);
    2. var stream = new CryptStream(file, this.Keyt);
    3. return AssetBundle.LoadFromStream(stream, 0, this.ReadBufferSize);
    And the CryptStream is like this:
    Code (CSharp):
    1.     /// <summary>
    2.     /// The crypt stream used to crypt a stream.
    3.     /// </summary>
    4.     public sealed class CryptStream : Stream, IDisposable
    5.     {
    6.         private Stream source;
    7.         private byte[] keyt;
    8.  
    9.         /// <summary>
    10.         /// Initializes a new instance of the <see cref="CryptStream"/> class.
    11.         /// </summary>
    12.         public CryptStream(Stream source, byte[] keyt)
    13.         {
    14.             this.source = source;
    15.             this.keyt = keyt;
    16.         }
    17.  
    18.         /// <inheritdoc/>
    19.         public override long Position
    20.         {
    21.             get { return this.source.Position; }
    22.             set { this.source.Position = value; }
    23.         }
    24.  
    25.         /// <inheritdoc/>
    26.         public override long Length
    27.         {
    28.             get { return this.source.Length; }
    29.         }
    30.  
    31.         /// <inheritdoc/>
    32.         public override bool CanWrite
    33.         {
    34.             get { return this.source.CanWrite; }
    35.         }
    36.  
    37.         /// <inheritdoc/>
    38.         public override bool CanSeek
    39.         {
    40.             get { return this.source.CanSeek; }
    41.         }
    42.  
    43.         /// <inheritdoc/>
    44.         public override bool CanRead
    45.         {
    46.             get { return this.source.CanRead; }
    47.         }
    48.  
    49.         /// <inheritdoc/>
    50.         public new void Dispose()
    51.         {
    52.             base.Dispose();
    53.             this.source.Dispose();
    54.         }
    55.  
    56.         /// <inheritdoc/>
    57.         public override void Close()
    58.         {
    59.             base.Close();
    60.             this.source.Close();
    61.         }
    62.  
    63.         /// <inheritdoc/>
    64.         public override void Flush()
    65.         {
    66.             this.source.Flush();
    67.         }
    68.  
    69.         /// <inheritdoc/>
    70.         public override long Seek(long offset, SeekOrigin origin)
    71.         {
    72.             return this.source.Seek(offset, origin);
    73.         }
    74.  
    75.         /// <inheritdoc/>
    76.         public override void SetLength(long value)
    77.         {
    78.             this.source.SetLength(value);
    79.         }
    80.  
    81.         /// <inheritdoc/>
    82.         public override void Write(byte[] buffer, int offset, int count)
    83.         {
    84.             var keptLen = this.keyt.Length;
    85.             var keptStart = this.source.Position % keptLen;
    86.             for (int i = 0; i < count; ++i)
    87.             {
    88.                 var keptPos = (keptStart + i) % keptLen;
    89.                 var bufPos = offset + i;
    90.                 buffer[bufPos] = (byte)(buffer[bufPos] ^ this.keyt[keptPos]);
    91.             }
    92.  
    93.             this.source.Write(buffer, offset, count);
    94.         }
    95.  
    96.         /// <inheritdoc/>
    97.         public override int Read(byte[] buffer, int offset, int count)
    98.         {
    99.             var keptLen = this.keyt.Length;
    100.             var keptStart = this.source.Position % keptLen;
    101.  
    102.             var readCount = this.source.Read(buffer, offset, count);
    103.             for (int i = 0; i < readCount; ++i)
    104.             {
    105.                 var keptPos = (keptStart + i) % keptLen;
    106.                 var bufPos = offset + i;
    107.                 buffer[bufPos] = (byte)(buffer[bufPos] ^ this.keyt[keptPos]);
    108.             }
    109.  
    110.             return readCount;
    111.         }
    112.     }
    I test the encrypt and decrypt with my own code with this stream is OK. And I read the document really carefully from here:
    https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromStream.html

    Especially the section:
    The following are restrictions on a Stream object to optimize AssetBundle data loading:

    Where am I missing?
     
  4. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Last edited: Jun 28, 2018
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    The more reliable approach is to submit a bug-report following these guidelines:
    https://unity3d.com/unity/qa/bug-reporting

    Using the official way makes sure the report is in Unity's bug-tracking pipeline and gets processed at one point.
     
  6. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Yes, I submit this bug a month ago. Finally I found I met the same problem.
    The most correct bug ID is 1026629