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 eniotna308 · Mar 29, 2014 at 03:32 AM · crash

Unity crash on my computer but not others.

I wrote a basic script for Unity in C#.

Everything was going well but during my latest tests, Unity freezed like if I launched an infinite loop. I didn't understand what was wrong so I gave my code to a friend to see if he could make it work. He got it working but after a while, there is an error about pointers. He gave it back to me and it still freeze my Unity. If I lauch the Debug, everything seem to be all right.

Do you understand what's wrong with this code? Does-it work on your computer? Should-I buy a new computer?

There is my code. To use it, include Decision and DigestiveSystem in an object. Decision's structure might seem weird but I want it to use a lot of other scripts without crashing if one is missing.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Decisions : MonoBehaviour
 {
     private List<string> Action;
     private List<double> Want;
     private bool exist_DS;
 
     private DigestiveSystem DS ;
 
     // Use this for initialization
     void Start ()
     {
         
         /*if (DS == null)
             Debug.Log ("null");
         else
             Debug.Log (DS.IntestinesPercentage);*/
         Action = new List<string>();
         Want = new List<double>();
         DS = null;
         exist_DS = false;
     }
 
     private void DSReady()
     {
         DS = GetComponent<DigestiveSystem> ();
     }
 
     private void DSInit()
     {
         Action.Add ("Eat");
         Action.Add ("Evacuate");
 
         Want.Add (1 - DS.StomachPercentage);
         Want.Add (DS.IntestinesPercentage);
         exist_DS = true;
     }
     // Update is called once per frame
     void Update ()
     {
         
         if (DS == null)
             Debug.Log ("null");
         else
             Debug.Log ("non-null");
         if (DS != null && exist_DS == false)
             DSInit ();
         /*if (exist_DS)
         {
             Debug.Log ("SP "+DS.StomachPercentage);
             Debug.Log ("IP "+DS.IntestinesPercentage);
         }*/
 
         int Maximum = GetWantMaxPos ();
         /*Debug.Log ("A.C "+Action.Count);
         Debug.Log ("W.C "+Want.Count);*/
         Debug.Log ("max "+Maximum);
 
         foreach(double d in Want)
         {
             Debug.Log("WANT: "+d);
         }
         /*if(Maximum!=-1)
         {
             switch (Action[Maximum])
             {
             case "eat":
                 Debug.Log("Eat");
                 GetComponent<DigestiveSystem>().Eat (1);
 
                 break;
             case "evacuate":
                 Debug.Log("Evacuate");
                 GetComponent<DigestiveSystem>().Evacuate();
 
                 break;
             }
         }*/
     }
     private int GetWantMaxPos()
     {
         int max = 0;
         for (int pos=0; pos<Want.Count; pos++)
         {
             if(Want[pos]>Want[max])
                 pos=max;
         }
         if (Want.Count == 0)
             max = -1;
         return max;
     }
 }



 using UnityEngine;
 using System.Collections;
 
 public class DigestiveSystem:MonoBehaviour
 {
     private Organ stomach;
     private Organ intestines;
     private bool IsInit;
 
     public double StomachPercentage
     {
         get{ return stomach.Percentage;}
     }
     public double IntestinesPercentage
     {
         get{ return intestines.Percentage;}
     }
     // Use this for initialization
     void Start ()
     {
         stomach = new Organ (90,100,1);
         intestines = new Organ (30,100,1);
 
         IsInit = false;
     }
     
     // Update is called once per frame
     void Update ()
     {
         if (IsInit == false)
         {
             GetComponent<Decisions>().SendMessage("DSReady");
             IsInit=true;
         }
 
         intestines.Add(stomach.Remove (Time.deltaTime));
         /*Debug.Log (Time.timeSinceLevelLoad);
         Debug.Log (stomach.Percentage);
         Debug.Log (intestines.Percentage);*/
     }
 
     public void Eat( double Qt)
     {
         stomach.Add (Qt);
     }
     public double Evacuate()
     {
         return intestines.Remove (Time.deltaTime);
     }
 }
 



 using UnityEngine;
 using System.Collections;
 
 public class Organ
 {
 
 
     private double Quantity;
     private double Max;
     private double Speed;
 
     public double Percentage
     {
         get{ return Quantity / Max;}
     }
     public Organ(double start_Quantity, double start_Max, double start_Speed)
     {
         Quantity = start_Quantity;
         Max = start_Max;
         Speed = start_Speed;
     }
 
     public void Add(double Qt)
     {
         Quantity += Qt;
     }
     public double Remove(double time)
     {
         double Qt = Speed * time;
         if (Quantity < Qt)
             Qt = Quantity;
         Quantity -= Qt;
         return Qt;
     }
 
 }
 
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

20 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

Related Questions

This code crashes unity, please help! 0 Answers

Instantiate 697283 trees by script? Crash! 2 Answers

Unity 4.5 crashes iMAC (Maverick) while trying to open a script 1 Answer

Can't open script via Visual Studio (only last 2 days) 3 Answers

What can cause Unity to crash? 3 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