diff --git a/assets/index.html b/assets/index.html
index 3c1fe56..5ab8801 100644
--- a/assets/index.html
+++ b/assets/index.html
@@ -145,12 +145,20 @@
draw() {
this.triangles.sort((a, b) => b.depth - a.depth);
this.triangles.forEach(tri => {
- const proj1 = tri.p1.project();
- const proj2 = tri.p2.project();
- const proj3 = tri.p3.project();
+ if (!tri || !tri.p1 || !tri.p2 || !tri.p3) return;
- const v1 = { x: tri.p2.x - tri.p1.x, y: tri.p2.y - tri.p1.y, z: tri.p2.z - tri.p1.z };
- const v2 = { x: tri.p3.x - tri.p1.x, y: tri.p3.y - tri.p1.y, z: tri.p3.z - tri.p1.z };
+ const p1 = tri.p1;
+ const p2 = tri.p2;
+ const p3 = tri.p3;
+
+ const proj1 = p1.project();
+ const proj2 = p2.project();
+ const proj3 = p3.project();
+
+ if (!proj1 || !proj2 || !proj3) return;
+
+ const v1 = { x: p2.x - p1.x, y: p2.y - p1.y, z: p2.z - p1.z };
+ const v2 = { x: p3.x - p1.x, y: p3.y - p1.y, z: p3.z - p1.z };
const crossZ = v1.x * v2.y - v1.y * v2.x;
if (crossZ >= 0) return;