Search Unity

Instantiate(www.assetBundle.mainAsset) cause EXC_BAD_ACCESS(SIGABRT)

Discussion in 'iOS and tvOS' started by liudibo, Apr 9, 2011.

  1. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
    I use the simple editor script to generate an asset bundle from a prefab object:
    Code (csharp):
    1.  
    2. Object o = Selection.activeObject;
    3. string named = "Panorama.assetbundle";
    4. string pathd = Application.dataPath + "/../AssetBundles/" + named;
    5. BuildPipeline.BuildAssetBundle(o, null, pathd, BuildAssetBundleOptions.CollectDependencies, BuildTarget.iPhone))
    Then I use the following code to load and instantiate it at runtime:
    Code (csharp):
    1.  
    2.        IEnumerator Start () {
    3.         WWW www = new WWW("file://" + Application.dataPath + "/../AssetBundles/Panorama.assetbundle");
    4.         yield return www;
    5.        
    6.         if (www != null  www.error == null) {
    7.             if (www.assetBundle == null) {
    8.                 _error.text = "assetBundle null";
    9.             } else if (www.assetBundle.mainAsset == null) {
    10.                 _error.text = "mainAsset null";
    11.             } else {
    12.                 _error.text = "no error";
    13.                 Instantiate(www.assetBundle.mainAsset);
    14.             }
    15.         } else {
    16.             _error.text = www.error;
    17.         }
    18.     }
    19.  
    If I comment out Instantiate() function, everything works fine, I can see "no error" is displayed on the screen. But If I instantiate it, it will crash on iPad device but works well in the Unity Editor.

    I have no idea about why app crash with EXC_BAD_ACCESS, seems nothing is null.

    Thanks for help.
     
    Last edited: Apr 9, 2011
  2. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
    Here is the track stack in the crash log:
    Code (csharp):
    1.  
    2. Incident Identifier: 3F266150-ECAD-43FD-AC7C-B683487D7316
    3. CrashReporter Key:   eec4003da988ddecc3b78885b9c4f0dd44ea3ae1
    4. Hardware Model:      iPad1,1
    5. Process:         TestProject [1266]
    6. Path:            /var/mobile/Applications/618EB3B3-0383-4538-A7AD-F8F76E0E8E2E/TestProject.app/TestProject
    7. Identifier:      TestProject
    8. Version:         ??? (???)
    9. Code Type:       ARM (Native)
    10. Parent Process:  launchd [1]
    11.  
    12. Date/Time:       2011-04-09 23:04:16.726 +0800
    13. OS Version:      iPhone OS 3.2.2 (7B500)
    14. Report Version:  104
    15.  
    16. Exception Type:  EXC_BAD_ACCESS (SIGABRT)
    17. Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000
    18. Crashed Thread:  0
    19.  
    20. Thread 0 Crashed:
    21. 0   libSystem.B.dylib               0x000790a0 __kill + 8
    22. 1   libSystem.B.dylib               0x00079090 kill + 4
    23. 2   libSystem.B.dylib               0x00079082 raise + 10
    24. 3   libSystem.B.dylib               0x0008d20a abort + 50
    25. 4   TestProject                     0x00a9aff8 0x1000 + 11116536
    26. 5   TestProject                     0x00a83a9c 0x1000 + 11020956
    27. 6   libSystem.B.dylib               0x00077ba4 _sigtramp + 36
    28. 7   TestProject                     0x00705dc0 0x1000 + 7359936
    29. 8   TestProject                     0x00704f88 0x1000 + 7356296
    30. 9   TestProject                     0x006e4bbc 0x1000 + 7224252
    31. 10  TestProject                     0x00079190 0x1000 + 491920
    32. 11  TestProject                     0x0001f380 0x1000 + 123776
    33. 12  TestProject                     0x0079c2b4 0x1000 + 7975604
    34. 13  TestProject                     0x00799d3c 0x1000 + 7966012
    35. 14  TestProject                     0x0082b6e4 0x1000 + 8562404
    36. 15  TestProject                     0x006fa29c 0x1000 + 7312028
    37. 16  TestProject                     0x007c56cc 0x1000 + 8144588
    38. 17  TestProject                     0x00829104 0x1000 + 8552708
    39. 18  TestProject                     0x00017050 0x1000 + 90192
    40. 19  CoreFoundation                  0x00028ff4 -[NSObject performSelector:withObject:] + 16
    41. 20  Foundation                      0x0007cec8 __NSThreadPerformPerform + 228
    42. 21  CoreFoundation                  0x00022c0e CFRunLoopRunSpecific + 1822
    43. 22  CoreFoundation                  0x000224da CFRunLoopRunInMode + 42
    44. 23  GraphicsServices                0x000030d4 GSEventRunModal + 108
    45. 24  GraphicsServices                0x00003180 GSEventRun + 56
    46. 25  UIKit                           0x0000342a -[UIApplication _run] + 374
    47. 26  UIKit                           0x00001954 UIApplicationMain + 636
    48. 27  TestProject                     0x0001836c 0x1000 + 95084
    49. 28  TestProject                     0x00016ef8 0x1000 + 89848
     
  3. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
    I also want to describe the steps that I create the prefab:

    1. Create an empty prefab
    2. Create a cube GameObject in the Hierarchy and assign the textures
    3. Drag the cube to the prefab
    4. Click the prefab and use the editor script shown above to generate the asset bundle

    Anything wrong with these steps?
     
  4. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
    It's really easy to reproduce this crash problem by using this example:

    View attachment $crash.zip

    Generate the Xcode project directly from this unity project and compile it. Maybe you have to copy AssetBundles folder to the app manually. Then test it on iPad ... Crash!!

    I'm using Unity 3.3.0f4 and Xcode Version 3.2.3
     
  5. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Hi,
    your project is using stripping and in combination with asset bundles it requires additional attention to details. Code stripping is based on idea to remove parts of Unity runtime that aren't directly used neither from scripts nor from scenes that are included into build. The problem arises when assetbundles include types of assets that are absent both in game scripts and scenes included into build. Runtime parts responsible for these assets are just missing because of being stripped by linker.

    There are several ways to deal with this problem:
    a) Add dummy variables to your scripts that reference Types that are included into your assetbundles and so preserve parts of Unity runtime from stripping.
    b) Include dummy scene into build that references all the Types that are included into your assetbundles.

    P.S. while developing your assetbundle prototype also might consider to disable stripping.
     
    muldercnc likes this.
  6. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
    Many thanks! It's very very helpful.
     
  7. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
    I try to disable the strip mode and everything works fine. Now I want to try and add some dummy variables because disable strip will increase 8+MB to the app package. How to figure out which types I'm using in the asset bundle and how to write the dummy code? Just simply add a declaration like "private Material dummyMat;"?
     
  8. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
    I know how to write a dummy code: simply declare a variable, never use it :)

    But still I can't find a way to figure out all types I've used in the asset bundle.
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Potentially stupid question mantasp, but I think I got something twisted up: Since when should classes used in asset bundles have an impact on stripping at all given they are not reflected, cause asset bundles don't transport code and assemblies (at least didn't do prior 3.3), the code so far always was part of the built player only and that one is independent of asset bundle presence.

    I though see why other aspects should be of importance (inbuilt components), for example if the scenes in the client don't use any physics but the asset bundles do, in which case physics would be missing after stripping if not added previously to the present scenes in some form and things like this.
     
  10. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Native code stripping which depends on scene assets and scripts was introduced with Unity 3.0 and in usual cases it allows to strip multiplayer networking, physics and some other stuff if it's not used. Asset bundles in this case are quite similar to reflection, because they depend on some strippable builtin components and this dependency is known only at runtime.

    This is a bit tough case for such a small synthetic cases, but usually isn't that big problem for real world big application, because they almost always have references to the builtin components in scripts or in main scenes that are distributed with main application.

    P.S. using editor scripts you can get dependencies of your editor selection and then getting list of used components is easy. http://unity3d.com/support/documentation/ScriptReference/EditorUtility.CollectDependencies.html
     
  11. Fooo

    Fooo

    Joined:
    Mar 11, 2011
    Posts:
    41
    +1000 this. I had a problem using streaming levels and disabling stripping solved it. Alternative is to create some dummy objects that use the missing components I guess.
     
  12. sebrk

    sebrk

    Joined:
    Mar 20, 2012
    Posts:
    13
    I waking this thread again. I'm having troubles with the stripping. I want to download an AssetBundle containing an object + textures and instantiate. It crashes when trying to instantiate. I do this because I would like to save app size so creating a dummy scene is pretty useless I guess as it would make no benefit in size?

    Say this AssetBundle includes a Cube (+Material and Texture). How would I create dummy references for this?
     
  13. alexfoo

    alexfoo

    Joined:
    Dec 6, 2010
    Posts:
    2
    Can refer here for the 'cube + texture' problem: http://forum.unity3d.com/threads/88080-IOS-stripping-and-Instantiate
     
  14. lostplesed

    lostplesed

    Joined:
    Mar 26, 2014
    Posts:
    25
    thanks a lot!