KevinBLT Posted June 23, 2016 Share Posted June 23, 2016 Hello, I have the following error when I try to clone an object. Uncaught TypeError: Cannot set property 'references' of null What can I do? Why does this happen? Best regards Kevin Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 23, 2016 Share Posted June 23, 2016 Hey Kevin, can you repro on the playground? Quote Link to comment Share on other sites More sharing options...
KevinBLT Posted June 27, 2016 Author Share Posted June 27, 2016 I think I've found it. I sometimes had leaks while cleaning up (disposing). I had similar problems some minutes ago while using CSG. I would highly appreciate to throw an error when the object is disposed or _geometry is null. For example: ________________________________ Babylon.js - CSG.FromMesh - Starting column: 31193 var indices = mesh.getIndices(), positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind), uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind); // ============> If indices,positions, normals or uvs are null or there aren't any submeshes there will be unforeseen results Better would be to throw an error // <============= var subMeshes = mesh.subMeshes; for (var sm = 0, sml = subMeshes.length; sm < sml; sm++) { for (var i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) { vertices = []; for (var j = 0; j < 3; j++) { var sourceNormal = new BABYLON.Vector3(normals[indices[i + j] * 3], normals[indices[i + j] * 3 + 1], normals[indices[i + j] * 3 + 2]); uv = new BABYLON.Vector2(uvs[indices[i + j] * 2], uvs[indices[i + j] * 2 + 1]); var sourcePosition = new BABYLON.Vector3(positions[indices[i + j] * 3], positions[indices[i + j] * 3 + 1], positions[indices[i + j] * 3 + 2]); position = BABYLON.Vector3.TransformCoordinates(sourcePosition, matrix); normal = BABYLON.Vector3.TransformNormal(sourceNormal, matrix); vertex = new Vertex(position, normal, uv); vertices.push(vertex); } polygon = new Polygon(vertices, { subMeshId: sm, meshId: currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex }); // To handle the case of degenerated triangle // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated if (polygon.plane) polygons.push(polygon); } } var csg = CSG.FromPolygons(polygons); _________________________ I had some troubles to find the problem. In this case "polygons" is an empty array and will lead to some "funny" errors in the result mesh (after subtract, union, whatever) ;-) Thank you and best regards Kevin Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 27, 2016 Share Posted June 27, 2016 Ok gotcha! Feel free to submit a PR for this good idea Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.