error in HTML5 only.

Monkey Forums/Monkey Programming/error in HTML5 only.

Jesse(Posted 2011) [#1]
some how an object becomes null after a certain amount of time of being executed.
this same code works fine executed for different platforms. It works as expected in GLFW and Flash.

tested on my Mac with google chrome and safari, fails with both on MonkeyPro V33.




skid(Posted 2011) [#2]
I think your program needs to be a little more sensitive to when Millisecs returns 0, which it can do on the first Update. If I add this code to the top and call Tick from OnUpdate I can't get it to break, if the Tick call is moved to after game.Update then the code breaks.


Global ftime%

Function Millisecs%()
Return ftime
End

Function Tick:Void()
ftime+=20
End



Jesse(Posted 2011) [#3]
I don't know if we are talking about the same thing and excuse me if I miss interpret your post.
I know that the code is not logically correct but the problem is that it is returning a "NAN" for a an object variable value that is predefined once at the beginning of the application. It's the object "myOB" in the global "game" object and only values are moved in to it.

in which case it should return at least Zeros but Both of the values for the DrawText are displayed as "NAN" which should not happen at all as if myOb became null after a certain time. sometimes it takes a while sometimes it happens right away.


marksibly(Posted 2011) [#4]
Hi,

Nans generally indicate a math error such as sqrt(-1). They propagate through any calculations too, so if an expression has just one nan in it, the result is nan.

And it's not unusual to get nans on one target but not another - it'll depend on what FPU modes are in effect.

I don't get what you mean by 'predefined once at the beginning of the application' though - the myOb.p0 and p1 fields are being constaly updated as far as I can tell, as are myOb.vx and vy.

But it's a fairly long piece of code - can you try trimming it down a bit?


marksibly(Posted 2011) [#5]
Hi,

Well, sort of related to what skid was saying...

If I add this to updateObject:Void(v:TVector) after the "Local time:Float=..." calculation:

If time=0 Return

...it's fixes the nans here.

This may be to do with the new update timing code, which will now execute multiple 'OnUpdates' if necessary to catch up with any lost time. This also appears to happen in flash, and it's something you'll need to allow for. It's probably not happening in glfw/xna because there is much less 'performance noise' compared to browser based stuff.

I'm still a bit confused about why 'delta timing' is so popular - update rate should be reliable (over time anyway, to allow for glitches/spikes - and now that html5 has been fixed!) so 'time delta' should be constant.


Jesse(Posted 2011) [#6]

I don't get what you mean by 'predefined once at the beginning of the application' though - the myOb.p0 and p1


I meant instantiate it as in "new" sorry.

Thanks Mark. I knew about -1 producing the imaginary number but I completely felt out of my mind.
on the other hand I did some test and it seems that Sqrt(0) is giving me that error of which I don't know if it's correct or not.


Jesse(Posted 2011) [#7]
Its the division by zero following the sqrt.



solved thanks!


marksibly(Posted 2011) [#8]
Hi,

You're right, sqrt(0) appears to be giving a nan in javascript and actionscript!

I think this may be because it's actually doing sqrt(-0). In FP, 0 can be positive or negative (I think, it's been a while...). Another source of nans can be 0/0 if I remember correctly.


Jesse(Posted 2011) [#9]
yea same error.
is there a way to to test if a Sqrt is returning a value or a nan?


marksibly(Posted 2011) [#10]
Hi,

Actually, I don't think it is the sqrt.

When time is 0, v.vx, v.vy, v.length all become 0.

It's the v.dx=v.vx/v.length stuff that comes a bit later that's causing the nans - ie: 0/0.


marksibly(Posted 2011) [#11]
Hi,

To fix it, I think you'll have to:

* Check for elapsed time=0 in OnUpdate and do nothing, AND...

* Check for v.length>0 before updating v.dx,v.rx,v.lx etc. eg:

		If v.length>0
			'normalized unti-sized components
			v.dx = v.vx/v.length
			v.dy = v.vy/v.length
			'Right hand normal
			v.rx = -v.vy
			v.ry = v.vx
			'Left hand normal
			v.lx = v.vy
			v.ly = -v.vx
		Else
			v.dx=0
			v.dy=0
			v.rx=0
			v.ry=0
			v.lx=0
			v.ly=0
		Endif


This is because, even if time elapsed is >0, it's still possible for v.length (and therefore v.vx and v.vy) to be 0 - ie: if the ball is at the 'peak' of it's bounce and therefore momentarily stationery.

All in all, I'd say you're getting bitten by the 0/0 nan, not the sqrt nan.

And I still don't get the delta timing...


Jesse(Posted 2011) [#12]
yea Mark. All of the problems are in the division by zero. I been checking all of the divisions and sooner or later they end up being a nan. it's all my bad logic.

Thanks, Thanks. Thanks......

I would had never created this problem if it had not being that I never expected to deal with "NAN"'s.

there is also an error in the t1 and t2 with the perps division.