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.

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


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

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