From 3d27de4fc3133174cbd4c788051d2fcf4cb24759 Mon Sep 17 00:00:00 2001
From: Greg Fodor <gfodor@gmail.com>
Date: Sun, 21 Oct 2018 17:24:10 +0000
Subject: [PATCH] Check for empty bounding box case

---
 src/components/media-loader.js |  2 +-
 src/utils/auto-box-collider.js | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/components/media-loader.js b/src/components/media-loader.js
index 5dcd47bee..6aca6ec6e 100644
--- a/src/components/media-loader.js
+++ b/src/components/media-loader.js
@@ -42,7 +42,7 @@ AFRAME.registerComponent("media-loader", {
     if (this.el.body && this.shapeAdded && this.el.body.shapes.length > 1) {
       this.el.removeAttribute("shape");
       this.shapeAdded = false;
-    } else if (!this.hasBakedShapes) {
+    } else if (!this.hasBakedShapes && !box.isEmpty()) {
       const center = new THREE.Vector3();
       const { min, max } = box;
       const halfExtents = {
diff --git a/src/utils/auto-box-collider.js b/src/utils/auto-box-collider.js
index 0a8b69037..cfb8882fa 100644
--- a/src/utils/auto-box-collider.js
+++ b/src/utils/auto-box-collider.js
@@ -1,17 +1,25 @@
 const rotation = new THREE.Euler();
 export function getBox(entity, boxRoot) {
   const box = new THREE.Box3();
+
   rotation.copy(entity.object3D.rotation);
   entity.object3D.rotation.set(0, 0, 0);
   entity.object3D.updateMatrixWorld(true);
+
   box.setFromObject(boxRoot);
-  entity.object3D.worldToLocal(box.min);
-  entity.object3D.worldToLocal(box.max);
-  entity.object3D.rotation.copy(rotation);
+
+  if (!box.isEmpty()) {
+    entity.object3D.worldToLocal(box.min);
+    entity.object3D.worldToLocal(box.max);
+    entity.object3D.rotation.copy(rotation);
+  }
+
   return box;
 }
 
 export function getScaleCoefficient(length, box) {
+  if (box.isEmpty()) return 1.0;
+
   const { max, min } = box;
   const dX = Math.abs(max.x - min.x);
   const dY = Math.abs(max.y - min.y);
-- 
GitLab