Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 fkjaha_unity · May 27, 2020 at 12:43 PM · crashrandomcrashingvaluescrashes

Unity crashes after I change 1 symbol in code!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class FlorScript : MonoBehaviour
 {
     public int size, sizeleft;
     public int[] sizeX;
     public int a,b,c;   
 
     public GameObject[] objts;
     // public GameObject lastspwnd;
     public GameObject pos1;
      
     public bool isSpace;
 
 
     private void Start()
     {
         sizeleft = size;
         a = Random.Range(0, 3);
         Instantiate(objts[a], pos1.transform.position, pos1.transform.rotation);
         sizeleft -= sizeX[a];
         pos1.transform.position -= new Vector3(-3f, 0, 0);
         isSpace = false;
         Log(a," <-- First random");
         for(int i = 0; i <= 10; i++) //How many objects we can spawn;
         {
             for(int k = 0; k <= 3; k++)  //Check if there are object that can fill empty space;
             {
                 isSpace = false;  // isSpace set to false to avoid issues;
                 if(sizeleft >= sizeX[k]) // If Yes than stop check;
                 {
                     isSpace = true;
                     Log(k, "  break");
                     break;
                 }
             }
             if (!isSpace) // If ther is not empty space than STOP
             {
                 break;
             }
             if (isSpace) // Start searching desired object;
             {
                 while (isSpace) //repeat cheking until the desired object is found;
                 {
                     a = Random.Range(0, 3);
                     **if (sizeleft >= size[a])  
                     {
                         Instantiate(objts[a], pos1.transform.position, pos1.transform.rotation);
                         sizeleft -= sizeX[a];
                         isSpace = false;
                         break;
                     }**
                 }
 
             }
             
             
         }
         
     }
 
     public void Log(int value, string massage)
     {
         Debug.Log(value + " || " + massage);
     }
 }
 

When I change ">=" to "<=" in last if it work but on the other wrong way. But if I left everything without changes then Unity crashes and i need to restart it; What's wrong? Thanks) P.S. I'm not a native English speaker)

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

1 Reply

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

Answer by unity_ek98vnTRplGj8Q · May 27, 2020 at 02:51 PM

sizeLeft is probably never less than any of the values in the size array, and you are getting stuck in an infinite while loop because isSpace is never being set to false. Make sure that you either are guaranteed to exit the while loop or that you force it to exit after a few loops.

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 fkjaha_unity · May 27, 2020 at 07:29 PM 0
Share

O$$anonymous$$G, I understand that one of the sizeX is zero and because of it first for loop says that isSpace is true after what while loop became infinity. THANKS!)))

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

141 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Random crash in ntdll.dll 0 Answers

Game no reopen before go to Desktop or something (FullScreen) 0 Answers

Unity Editor Crashes Upon Startup 0 Answers

Unity crashing constantly 2 Answers

Unity crashes at anything (almost literally) 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