Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Hivemind · Jan 18, 2013 at 05:53 AM · editorcrashmemorystackoverflow

Editor Crashes when spawning 1k objects

Hey Guys,

I have a tool that spawns nodes that I use for pathfinding. Each node contains 5-6 floats and a list of its neighbors(max of 8, lists aren't optimized). Anyways, when i try to relaunch a scene that contains ~1600 nodes, the editor crashed giving me the following error ...

System memory in use: 22.2 MB. Failed to postprocess stacktrace StackOverflowException

If I make 1000 nodes, the editor is fine ...

Any general ideas on how I can decrease the memory put onto the stack? I don't create any local variables while i loop and create the nodes.

Also, any explanation of how the stack works in depth would be appreciated. I'm using "new" and allocating most of the memory on the heap so I don't know why the stack is getting so large.

I provided some code/pseudocode that explains the logic of how path node are generated.

 Class pathNode
 {
     int cost;
     list<pathNode> neighbors
 }
 
 //Spawning code
 
 GameObject[] nodeList = new GameObject[num_collumns * num_rows];
 for(int x = 0, x < num_collumns; x++)
 {
     for(int y = 0; y < num_rows; y++)
     {
         index = x + (y * num_collumns);
         Gameobject newNode = Instantiate(PathNodePrefab, new Vector3(x, 0, y), Quaternion.Identity); 
         newNode.getcomponent<pathNode>().Initialize();
         nodeList[index] = newNode;
     }
 }
 
 //Figuring out neighbors
 bool bLeft, bTop, bRight, bBottom;
 
 for(int x = 0, x < num_collumns; x++)
 {
     for(int y = 0; y < num_rows; y++)
     {
         index = x + (y * num_collumns);
         currentNode = nodeList[index];
 
         //index into it's left, right, top ,bottom and set booleans to whether it is an existing index
         //using that data, you can figure out LeftTop, RightTop, LeftBottom, RightBottom
 
         currentNode.neighbors.add( ) // add every adjacent neighbor
 
 
     }
 }


note: Everything happens when the simulator isn't running. I use a custom editor script to create these nodes. After 1.6k node objects are created, I save the scene. When i reload the scene, Unity would crash.

Comment
Add comment · Show 5
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
avatar image robertbu · Jan 18, 2013 at 03:20 PM 0
Share

Can you post your code?

avatar image Hivemind · Jan 18, 2013 at 04:14 PM 0
Share

Added some code that might help explain what I'm doing.

avatar image robertbu · Jan 18, 2013 at 04:55 PM 0
Share

Google 'Call Stack' for information on the stack. Wikepida has an artilce http://en.wikipedia.org/wiki/Call_stack. And the call stack error may not be the base error in this case. Your StackOverflowException is occurring when doing the backtrace. That is when trying to report the calling chain for the error. This might happen if the underlying problem is a stack overflow, but not for sure.

As for number of scene objects being the problem, you can run a simple test to see if that is the root of the issue. Run your script with 1000 nodes, save the scene, run your script again to produce an additional 1000 nodes, save the scene.

If the issue is too many objects you will crash on second reload. If not, I'd be looking at any relationship between the game object that Unity might walk using recursion. For example, are you using the partent/child relationship in the transform between your game objects?

avatar image robertbu · Jan 18, 2013 at 05:17 PM 0
Share

As a quick test, I wrote an editor script that spawned 10,000 cube object. Each object had a script containing two Vector3's and two floats. No problems saving and reloading. Though if it is a stack problem, stack size can vary from one machine to another.

avatar image Skeledurr · Mar 05, 2015 at 04:08 AM 0
Share

I just ran into the same problem. Editor script creates nodes, save scene, when I play the scene or reload the scene Unity crashes. If I reduce the node count it works fine.

Did you resolve your problem?

I just completed further testing. I found if I adjust my node scale to 0.04f from 0.05f it worked. I can then play the scene. When I stop the scene I can adjust the scale back to 0.05f and replay the scene without it crashing.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jan 18, 2013 at 08:42 AM

A Stackoverflow means you have created some kind of circular reference or infinite recursion somewhere. How does your "nodes" looks like? Is it a MonoBehaviour? How does the neighbor array / list looks like? Is it public or private / protected? How is the array populated?

Also what means "relaunch" in your case? Do you mean open the scene in the editor or loading the level at runtime?

Comment
Add comment · Show 1 · Share
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
avatar image tigertrussell · Mar 05, 2015 at 04:11 AM 0
Share

A stack overflow does not necessarily mean you have infinite recursion or circular references; it is merely a likely culprit.

avatar image
0

Answer by Loius · Jan 18, 2013 at 07:47 AM

Creating that many objects at once is the problem (and it's often recommended to keep as few real objects as possible). If you convert your nodes into simple classes with positional data (and you could write an editor tool to do the conversion and store the info in a single object), you'll be able to create "as many as you want" at once.

If they're Game Objects, there's just no way to make that many at once. You could try reducing the number spawned per frame (using a coroutine or the like).

Comment
Add comment · Show 1 · Share
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
avatar image Hivemind · Jan 18, 2013 at 03:45 PM 0
Share

Good advice. I am spawning them as game objects so I can see the meshrenderer (cube primitive). I will probably have to include the visuals some other way and separate the data by itself.

The coroutine idea is pretty cool but I didn't know if that would work when you're project isn't playing. I am creating these objects with an editor tool and Unity crashes when I save the scene and re-enter the scene. The game isn't playing on any of these steps.

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Running out of memory upon re-import and update 0 Answers

Editor crash after editing in a better computer 0 Answers

Help when playing in Editor , Big memory Leak/problem 0 Answers

Unity crashes from materials 1 Answer

Editor crash on all scenes and projects 1 Answer


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