- Home /
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.
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.
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 :)
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.
Your answer
Follow this Question
Related Questions
Dictionary Function not responding to Key Calls 0 Answers
NullReferenceException on function call 1 Answer
Null Reference Expantion 1 Answer