D3js & ThreeJS 3D visualisation which produces Mozilla TypeError in certain circumstances