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 drudiverse · Jul 18, 2014 at 02:03 PM · nullreferenceexceptionfunction

Function is Null. It's not possible. why.

I have a function drawline(x,y,z,angle,iteration):ienumerator ...

it works 1 or 2 thousand times flawlessly and then suddenly it prints:

 nullreference exception at line: .... function drawline(x,y,z,angle,iteration)...

sometiems the program runs on, sometimes the code is jammed and doesnt run on next keypress.

if i write function drawline(x,y,z,angle,iteration) WIthouth IEnumerator, the null reference is never printed, but the code eventually stops running after 2-3 minutes.

So naturally, i printed all the inputs

                 if(x2 == null)print("x2wasnull");
                 if(y2 == null)print("y2wasnull");
                 if(z2 == null)print("z2wasnull");
                 if(y4 == null)print("y4wasnull");
                 if(depth-1 == null)print("dwasnull"); etc all inputs

and the function is null even though none of its imputs is null.

The pc is a dell from about 2007 running XP.

Comment
Add comment · Show 3
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 AlkisFortuneFish · Jul 18, 2014 at 02:17 PM 0
Share

What types are the inputs? Value types, such as int and float, as well as structs like Vector3, are not nullable. They cannot be null at all and any == null check will always return false. The problem is inside the function, and impossible to find without looking at the code for that function.

avatar image Xtro · Jul 18, 2014 at 03:21 PM 0
Share

can you please copy the entire code.

avatar image drudiverse · Jul 18, 2014 at 03:24 PM 0
Share

The inputs are all float and depth is integer.

because it happens only once every 20-30 odd times, i.e. the function runs at least 20000 times without errors, i think it's a problem with my laptop.

perhaps $$anonymous$$athf.Cos(angle1 deg_to_rad)* is returning NaN values that the processor is aborting,

Thanks for telling me to check depth, i took a fresh look at it and noticed i had left in an experimental function that wasnt well written:

 function fs (a:float):float{    
     return 1;// it was previously return $$anonymous$$athf.Pow(a*.5);
 }

that was causing the pc to make null exceptions far more often... even though the code isn't strictly error causing...

and the code was sometimes freezing on null errors because i had tried to stop the function twice while iterations > 0, isrunning = true.... it was aborting the function and not resetting isrunning .

it's a very rare error i think it will be ok in the home pc. sorry i spent more than 2 hours trying to figure out why the function was null :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Zodiarc · Jul 18, 2014 at 02:06 PM

I think you should check depth == null because if it is, depth - 1 will still cause the exception.

Basically:

depth == null => null == null => if statement works

depth-1 == null => null-1 == null => exception is being thrown.

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

23 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

Related Questions

Dictionary Function not responding to Key Calls 0 Answers

NullReferenceException on function call 1 Answer

Null Reference Expantion 1 Answer

How to call a function from another script - getting error "Object reference not set to an instance of an object" 5 Answers

C# Null Reference Exception in Custom Function 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