NeoSpark314/godot_oculus_quest_toolkit

Intermittent "Division By Zero in operator '/'." error with handtracking

jamesalbert opened this issue · 8 comments

This is happening intermittently in Feature_HandModel.gd in _track_average_velocity both in the demo scene and in my own incorporation of the script.

average_velocity = Vector3(0, 0, 0);
for i in range(0, _velocity_buffer_size): 
        average_velocity += _velocity_buffer[i]
		
>>> average_velocity = average_velocity * (1.0 / (_dt * _velocity_buffer_size));
	
_last_velocity_position = global_transform.origin;

I'm not sure if the right solution here is to add a very small buffer to _dt or if the function call should be skipped altogether if _dt == 0. Thoughts?

Godot version: 3.2 rc-1
toolkit version: head

edit: added screenshot with Godot version

Screen Shot 2020-01-19 at 2 54 29 PM

Thanks for reporting. I will have a look and try to figure out why this happens. An offset for _dt is probably not good as this will distort the velocity. Checking for == 0.0 (or < some division epsilon) will probably work but if _dt is 0.0 it would mean that the _process(_dt) funciton is called with 0.0 (or a very small value) which should not happen I think as it should be only called once per frame.
Do you know if this also happens on the oculus quest?

will try on the quest after work tonight 👍

I've ran this on the quest and it worked for the times that I did, but since it's intermittent I'll try a bunch of times and see if it crashes

I also did some testing now. So far I was not able to reproduce it on desktop. I tried current godot master and also the RC1 in the hand tracking demo application of the toolkit. How long was it usually until it happened for you? I printed the _dt value and it was always the expected 1/60s for normal desktop rendering at 60hz.

So after only adding a print_debug to print out _dt, this is what the crash looks like in the output. Odd


--- Debugging process started ---
Godot Engine v3.2.rc1.official - https://godotengine.org
OpenGL ES 2.0 Renderer: AMD Radeon Pro 555 OpenGL Engine
 
Registered camera FaceTime HD Camera (Built-in) with id 1 position 0 at index 0
Switching model for controller 'Not connected' (id 2)
_dt = 0.133333
   At: res://OQ_Toolkit/OQ_ARVRController/scripts/Feature_HandModel.gd:41:_track_average_velocity()
Switching model for controller 'Not connected' (id 1)
_dt = 0.133333
   At: res://OQ_Toolkit/OQ_ARVRController/scripts/Feature_HandModel.gd:41:_track_average_velocity()
_dt = 0.133333
   At: res://OQ_Toolkit/OQ_ARVRController/scripts/Feature_HandModel.gd:41:_track_average_velocity()
_dt = 0.133333
   At: res://OQ_Toolkit/OQ_ARVRController/scripts/Feature_HandModel.gd:41:_track_average_velocity()
_dt = 0.016667
   At: res://OQ_Toolkit/OQ_ARVRController/scripts/Feature_HandModel.gd:41:_track_average_velocity()
_dt = 0.016667
   At: res://OQ_Toolkit/OQ_ARVRController/scripts/Feature_HandModel.gd:41:_track_average_velocity()
_dt = 0
   At: res://OQ_Toolkit/OQ_ARVRController/scripts/Feature_HandModel.gd:41:_track_average_velocity()

I tried several more times on the quest not able to get it to fail. Safe to say this is only a pc thing for now

looks like _dt starts > 0, then a couple frames in turns into straight up 0

it's pretty infrequent, too. Out of about 10 times running it, it failed about twice

I added now a check for _dt <= 0.0 in the function to saveguard against this problem. I tried again but was not able to reproduce it on my machine. But there are probably a lot of things that could influence this. If you encounter other problems with the delta being 0 we could start investigating again. (Maybe its happening only for Radeon and not Nvidia); I would assume that this is a core issue though and has nothing to do directly with the toolkit.