Search Unity

Unity program hangs when adding script to gameobject..whyy?

Discussion in 'Scripting' started by michaljabrzyk, Jul 11, 2020.

  1. michaljabrzyk

    michaljabrzyk

    Joined:
    Apr 15, 2013
    Posts:
    57
    Hi. Litle problem. Unity Editor hangs and must be restarted when am adding this script to gameobject. Hope am not blind. Why happens? What's wrong with this code? Can anybody test it ? I create another project with same code but other name and unity hangs.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [ExecuteInEditMode]
    6.  
    7. public class A1 : MonoBehaviour
    8. {
    9.  
    10.     [Range(1, 360)]
    11.     public int _A = 2;
    12.     public int _C;
    13.     public int T;
    14.  
    15.     public int[] Points;
    16.     public int[] X_;
    17.     public int[] Y_;
    18.     public int[] Z_;
    19.  
    20.     private int Index_;
    21.     private int e;
    22.  
    23.     // Start is called before the first frame update
    24.     void Start()
    25.     {
    26.        
    27.     }
    28.  
    29.     // Update is called once per frame
    30.     void Update()
    31.     {
    32.         Debug.Log("Work's");
    33.  
    34.         Index_ = 0;
    35.         T = _A * _A;
    36.         _C = T * 3;
    37.  
    38.         Points = new int[_C];
    39.         X_ = new int[T];
    40.         Y_ = new int[T];
    41.         Z_ = new int[T];
    42.  
    43.         Cal();
    44.     }
    45.  
    46.     void Cal()
    47.     {
    48.         Debug.Log("Cal(); -- Initiation");
    49.         for (e = 1; e <= _A; e++)
    50.         {
    51.             Debug.Log("Cal(); -- First Loop");
    52.             Debug.Log("j = " + e);
    53.  
    54.             if (_A > 1) { Index_ = Index_ + 1; }
    55.  
    56.             for (; Index_ <= e + 2;)
    57.             {
    58.                 Debug.Log("Cal(); -- Secound Loop");
    59.                 Debug.Log("Index_ = " + Index_);
    60.             }
    61.         }
    62.     }
    63. }
    64.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    On line 56 you have a for loop where you're never changing the value of
    Index_
    and using it in the loop condition, so it's an infinite loop.