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 Dunkhan · Dec 04, 2011 at 02:24 PM · variabledebugprint

Inexplicable variable behaviour - debug help?

I am having the strangest issue. Building a mesh at runtime from scratch, a task which this particular piece of code successfully does over a hundred times before it crashes on one particular instance. The problem is with parsing an array of strings into a vector. It goes through 22335 vertices with no problem, but on the very last vertex it throws a wrong format exception on the parse line.

 objectMesh = new Vector3[int.Parse(numVertices)];
 for(j=0;j<objectMesh.length;j++)
 {
  var vertices = lines[i+j].Split(";"[0]);
  vertices = cleanStrings(vertices);        
  objectMesh[j] = Vector3(float.Parse(vertices[0]),float.Parse(vertices[1]),float.Parse(vertices[2]));
 }
 i+=j;

This is how the function works in every other model and for every other vertex of this model. There is a difference in this line in the source text, namely it is the last vertex, and has an extra delimiter(;) at the end. This means vertices is length 5 instead of length 4 after the split. I am not accessing verices[3] or [4] though so I don't see how this could be causing the problem.

I added a few different versions of debug output in to see what was going on. Replacing the last line with:

 var temp = new String[3];
 for(k = 0; k<3; k++)
 {
  if(modelPath.Contains("exec") && j>22000)
  {
    print(k);
    print(vertices[k]);
  }
  var temp2=vertices[k];
  temp[k]=temp2;
 }
 objectMesh[j] = Vector3(float.Parse(temp[0]),float.Parse(temp[1]),float.Parse(temp[2]));

Results in the final output

 2
 -0.064262

and then an index out of range exception on the line "var temp2=vertices[k];" So apparently it can print vertices[k] (-0.064262) but when I go to assign it to another variable the array has suddenly shrunk.

Another way I tried to debug was to replace the last line with

 if(modelPath.Contains("exec") && j>20000)
 {
  print(vertices.length);
  print(lines[i+j]);
  print(vertices[0] + "," + vertices[1] + "," + vertices[2]);
  print (vertices[1]);
 }
 var temp = new Vector3(float.Parse(vertices[0]),0,0);
 
 try
 {
  temp.y=float.Parse(vertices[1]);
  temp.z=float.Parse(vertices[2]);
 }
 catch(e)
 {
  print (vertices[1]);
 }
 objectMesh[j]=temp;

Which gives the output:

 5
       -0.014949; 0.559054;-0.064262;;
 -0.014949,0.559054,-0.064262
 0.559054

then the line "print (vertices[1]);" inside the catch prints an empty string, and then there is a format exception again.

So basically, vertex[1] is equal to 0.559054 until it tries to parse it into the vector, and then suddenly it is null.

As you might imagine my attempts to debug have made me more confused than before, this behaviour is outside of my experience and I can't make head or tail of it. Can anyone see anything I have missed?

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
0

Answer by aldonaletto · Dec 04, 2011 at 09:51 PM

The whole thing seems right; it's time to shoot in the dark. Could the last line have some non-printable character lost anywhere? Edit the text file and re-write the coordinates to check this. Could the routine be waiting for an extra vertex? Try to add some extra values after the last line, like this:

   -0.014949; 0.559054;-0.064262;0;0;0;

The null string inside catch may mean nothing: maybe the system just emptied the stack before jumping to the error routine.
Another thing: what does the function cleanStrings? Could it be messing the string due to the extra ;?

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

print(); to console problem - beginner 0 Answers

Debug.log,print not working when run from mobile android 0 Answers

Why is print() only in MonoBehaviour? 1 Answer

How do you print to the console/log from native code on OSX ? 1 Answer

Find variables based on value in debug mode 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