From db4a38ec03653bfa5b014ae6166e121957ea5c07 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 28 Aug 2025 20:50:24 +0200 Subject: [PATCH] fixed compile time errors; still runtime error inside mesh.render --- opengl_beginnings/src/custom/sphere_generator.rs | 7 ++++--- opengl_beginnings/src/engine/mesh.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/opengl_beginnings/src/custom/sphere_generator.rs b/opengl_beginnings/src/custom/sphere_generator.rs index 270fc07..8ce37b7 100644 --- a/opengl_beginnings/src/custom/sphere_generator.rs +++ b/opengl_beginnings/src/custom/sphere_generator.rs @@ -24,7 +24,7 @@ impl OctaSphere { pub fn render(&mut self, gl: &Context) { match self.mesh.as_mut() { None => {self.generate_sphere(); self.render(gl)}, - Some(mut mesh) => {mesh.render(gl)} + Some(mesh) => {mesh.render(gl)} } } @@ -65,12 +65,12 @@ impl OctaSphereGenerator { vertices.extend_from_slice(&base_vertices); // Create 12 edges, with n vertices added along them (n = numDivisions) - let mut edges = Vec::::with_capacity(12); + let mut edges: [Edge; 12] = Default::default(); for i in (0..vertex_pairs.len()).step_by(2) { let start_vertex = vertices[vertex_pairs[i]]; let end_vertex = vertices[vertex_pairs[i + 1]]; - let mut edge_vertex_indices = Vec::::with_capacity((num_divisions + 2) as usize); + let mut edge_vertex_indices = vec![0;(num_divisions + 2) as usize]; edge_vertex_indices[0] = vertex_pairs[i] as u32; // Add vertices along edge @@ -156,6 +156,7 @@ impl OctaSphereGenerator { } } +#[derive(Default)] struct Edge { vertex_indices: Vec, } diff --git a/opengl_beginnings/src/engine/mesh.rs b/opengl_beginnings/src/engine/mesh.rs index 86cd0c8..01b8825 100644 --- a/opengl_beginnings/src/engine/mesh.rs +++ b/opengl_beginnings/src/engine/mesh.rs @@ -24,7 +24,7 @@ impl Mesh { Self { vertices, indices, - normals: Vec::with_capacity(num_vertices), + normals: vec![Vector3::default();num_vertices], vao: None, vbo: None, ebo: None,