Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ZDFDigital · Jul 08, 2015 at 04:38 AM · editorcrashspritesatlas

Editor crashes when loading too many sprites (33) at runtime

Hey there,

in my game there is a part where you can put virtual stickers onto a background. On the bottom there is a menu with all the available stickers. This menu is filled at runtime. It's done by initializing a prefab and assigning a sprite to the SpriteRenderer component. All of the Sprites are in one atlas.

It works sometimes, but in most cases the editor crashes.

Here is the Code.

In the object, wich loads and holds the stickers:

 private void fillWithStickers (int tab)
 {
     float spaceBetweenStickers = 0.2f;
     float nextStickerPosition = spaceBetweenStickers;
     for (int i = 1; i <= numbersOfStickers[tab]; i++) {
         GameObject miniSticker = Instantiate (Resources.Load ("Prefabs/Sticker/MiniSticker", typeof(GameObject))) as GameObject;
         miniSticker.GetComponent<AutoSDSprites> ().loadSprite ("Sprites/Sticker/" + stickerNamePrefixes [tab] + "_mini", stickerNamePrefixes [tab] + "_" + i);
         float stickerWidth = miniSticker.GetComponent<SpriteRenderer> ().bounds.size.x;
         miniSticker.transform.SetParent (transform);
         miniSticker.transform.localPosition = new Vector2 (nextStickerPosition + (stickerWidth / 2.0f), 0);
         nextStickerPosition += spaceBetweenStickers + stickerWidth;
     }
     
     GetComponent<RectTransform> ().SetSizeWithCurrentAnchors (RectTransform.Axis.Horizontal, nextStickerPosition);
     float camHalfWidth = Camera.main.aspect * Camera.main.orthographicSize;
     maxX = (GetComponent<RectTransform> ().rect.size.x / 2) - camHalfWidth;
     minX = -maxX;
     transform.position = new Vector3 (maxX, transform.position.y);
 }

That's what the AutoSDSprites class is doing:

 public void loadSprite (string atlasPath, string spriteName)
 {
     atlasPath = applySDHDSuffix (atlasPath);
     GetComponent<SpriteRenderer> ().sprite = getSpriteFromSheet (Resources.LoadAll<Sprite> (atlasPath), spriteName);
     Resources.UnloadUnusedAssets ();
 }
 
 private Sprite getSpriteFromSheet (Sprite[] sprites, string spriteName)
 {
     foreach (Sprite s in sprites) {
         if (s.name == spriteName) {
             return s;
         }
     }
     return null;
 }

So what can I do? Where could the problem be?

EDIT: I found that the editor spits out this into the log, right before it crashes. Not just once, but a lot.

 NullReferenceException: Object reference not set to an instance of an object
 UnityEditor.InspectorWindow.Update () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1377)
 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
 Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
 System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
 UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:185)
 UnityEditor.HostView.Invoke (System.String methodName) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:178)
 UnityEditor.HostView.SendUpdate () (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:243)
 UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/editor/EditorApplicationBindings.gen.cs:264)

and this is thrown occasionally between the other

 NullReferenceException: Object reference not set to an instance of an object
 UnityEditor.InspectorWindow.ShouldCullEditor (UnityEditor.Editor[] editors, Int32 editorIndex) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1225)
 UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:962)
 UnityEditor.InspectorWindow.OnGUI () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:350)
 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)


EDIT2: I could replicate, when it crashes and when it doesn't. It crashes, if I have the GameObject with the fillWithStickers(int tab) method selected in the editor, when I run the game. I can live with that but it is sure annoying, if it crashes if I select the wrong item...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

sprite atlas late binding success but still render white,SpriteAtlas Use Case 0 Answers

Editor crash on max osx 0 Answers

Locking assembly reloading in editor 0 Answers

Editor crash on toggle with AA 2 Answers

Unity 2018.2.[1,2]f1 - Introduced artifacts to UI sprites at runtime 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges