From 338d5ec3bef6101027caca160c5e6a439b10e150 Mon Sep 17 00:00:00 2001 From: Tore Levenstam <152867686+rapid-images-tore-levenstam@users.noreply.github.com> Date: Fri, 28 Jun 2024 20:33:34 +0200 Subject: [PATCH] Throw error in CSG when adding a mesh that lacks indices, positions or normals (#15237) * throw error when mesh lacks indices, positions or normals * remove unused imports and added eslint ignores --- packages/dev/core/src/Meshes/csg.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/dev/core/src/Meshes/csg.ts b/packages/dev/core/src/Meshes/csg.ts index b50d5329ba7..2723cd1988e 100644 --- a/packages/dev/core/src/Meshes/csg.ts +++ b/packages/dev/core/src/Meshes/csg.ts @@ -1,4 +1,4 @@ -import type { Nullable, FloatArray, IndicesArray } from "../types"; +import type { Nullable } from "../types"; import type { Scene } from "../scene"; import { Quaternion, Matrix, Vector3, Vector2 } from "../Maths/math.vector"; import { VertexBuffer } from "../Buffers/buffer"; @@ -547,11 +547,24 @@ export class CSG { throw "BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh"; } - const indices = mesh.getIndices(), - positions = mesh.getVerticesData(VertexBuffer.PositionKind), - normals = mesh.getVerticesData(VertexBuffer.NormalKind), - uvs = mesh.getVerticesData(VertexBuffer.UVKind), - vertColors = mesh.getVerticesData(VertexBuffer.ColorKind); + const indices = mesh.getIndices(), + positions = mesh.getVerticesData(VertexBuffer.PositionKind), + normals = mesh.getVerticesData(VertexBuffer.NormalKind), + uvs = mesh.getVerticesData(VertexBuffer.UVKind), + vertColors = mesh.getVerticesData(VertexBuffer.ColorKind); + + if (indices === null) { + // eslint-disable-next-line no-throw-literal + throw "BABYLON.CSG: Mesh has no indices"; + } + if (positions === null) { + // eslint-disable-next-line no-throw-literal + throw "BABYLON.CSG: Mesh has no positions"; + } + if (normals === null) { + // eslint-disable-next-line no-throw-literal + throw "BABYLON.CSG: Mesh has no normals"; + } const subMeshes = mesh.subMeshes;