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 webe · Feb 03, 2015 at 04:57 AM · crashpathfindingloop

Unity crashes when doing A* pathfinding loop

I have a A* pathfinding class that I implemented myself with psuedocode as help. The program crashes when it is suppose to do a do-while loop that runs unitl target is found or the "OpenList" is empty. The problem seems to be with the OpenList, but I can't figure out what is wrong.

The list is an ArrayList and the loop runs while openList.Count is not 0. I did try to change the condition to just while pathFound == false, but it still crash. What happens when it crash is I can't do anything with Unity and windows labels it as "Not responding".

My own speculation is that it somehow becomes an infinite loop, but I've checked and double checked all functions and they work the way I want. It works when I remove the do-while loop and all values are what I expect them to be.

Well, this is my code. Can anyone find something that might cause the problem?

         do{            
             closedList.Add(current);    //Switch to closed list
             openList.Remove(current);
             
             neighbors = GetNeighbors(current);
             foreach (Node neighbor in neighbors){
 
                 if ((tileMap[neighbor.xpos, neighbor.zpos].Walkable()) && (!ClosedListContain(neighbor))){
 
                     if (!OpenListContains(neighbor)){///(!openList.Contains(neighbor)){ //
                         Debug.Log("Neighbor addede to openList");
                         
                         openList.Add(neighbor); //openList now contains this node
                         neighbor.SetParent(current);
                         SetScores(neighbor);
                     }
                     else{
                         Debug.Log("No neighbor added");
                         Node neighborClone = neighbor;
                         SetScores(neighborClone);
                         if (neighborClone.G < neighbor.G){ //Current path to this node is quicker
                             neighbor.SetParent(current);
                             SetScores(neighbor);
                         }
                     }
                 }
             }
 
             if (ClosedListContain(goal)){
                 pathFound = true;
                 break;
             }
 
         } while(openList.Count != 0);

Comment
Add comment · Show 1
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 SnotE101 · Feb 03, 2015 at 05:05 AM 1
Share

Your telling it to do whats in that loop while your open list is not 0. In your do loop you are adding to that list. So it never will stop.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SnStarr · Feb 03, 2015 at 07:41 AM

    } while(openList.Count != 0);

It will always be a number greater than 0 as you are adding something to list in your do loop. You will be forever stuck in that while loop because there will always be an item in the openList.count. Unity will not process endless loops. Break the loop or give it another statement.

Comment
Add comment · Show 2 · 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 webe · Feb 03, 2015 at 10:38 AM 1
Share

Yes I see the error now, thank you. The first thing to be done each loop is to get a new current, like this:

 current = GetNodeWithLowestF();

This way one value of the openList will be removed each loop. I can run the loop without crashing now. I even had that function written, I have no idea why it wasn't used. Stupid simple mistakes. Thank you and SnotE101 for pointing it out.

avatar image SnStarr · Feb 03, 2015 at 10:34 PM 0
Share

No problem, and good luck on future endeavors. Remember, logic always matters.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Loop crashing unity (pathfinding) 2 Answers

Unity crashes because of script 2 Answers

Logic question, unique path finding system 2 Answers

Pathfinding function crashes Unity? 1 Answer

Loop to populate array crashes Unity 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