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 Dan205 · Apr 29, 2012 at 02:03 PM · c#tutorialburgzergarcade

Hack and Slash tutorial Stack Overflow problem

Hello, I have followed the Hack and Slash tutorials by BurgZergArcade successfully up to number 30 (Or half way through it at least). At 4:34 on the video, when i try to save the vitals, unity says that I have a StackOverflowException. I am pretty sure from Google searches that this means I have an infinite loop of some kind, but I can't find where it is in my code and I can't find anyone else who has had the same problem. I am quite new to using CSharp in Unity and I was hoping that the tutorials would help me to improve, so it would be a great hep to me if someone could help me out. This is my code for saving the vitals:

 for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
     PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Base Value", pcClass.GetVital(cnt).BaseValue);
     PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Exp To Level", pcClass.GetVital(cnt).ExpToLevel);
     PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Cur Value", pcClass.GetVital(cnt).CurValue);
 }


Thanks,
Dan205

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

Answer by Bunny83 · Apr 29, 2012 at 02:23 PM

This piece of code can't cause a stackoverflow. Maybe your GetVital function is causing it. Are you even sure that this is causing it? Have you tried to comment out this part?

Infinite loops just freeze your application. The most common reason for a stack overflow is an end recursion. In other words a function is calling itself without a reasonable break-condition. This can be directly or indirectly.

 // direct:
 void Foo()
 {
    Foo();
 }
 
 // indirect:
 void Foo()
 {
    Bar();
 }
 void Bar()
 {
    Foo();
 }

Each function call will push the return address on the stack and create the local stack frame for the function. When the function exits this is cleaned up, but you never leave the function so the stack grow until you run out of stack memory.

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 Dan205 · Apr 29, 2012 at 02:28 PM 0
Share

Thank you! You're right. I commented each of the 3 playprefs out and found that the last one was the problem. I then looked at the original script (As you said, the GetVital() function) and found that in actual fact all it was was a capitalisation error. Silly me!

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

Multiple Cars not working 1 Answer

BurgZergArcade Unity tutorial 19-20 errors. 0 Answers

BurgZergArcade tutorial 20 errors? 0 Answers

Object doen't move even though i did according lesson 1 Answer

CharacterMotor CS Problem when export 0 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