fix a memory leak and most warnings

This commit is contained in:
griffi-gh 2023-01-29 01:28:00 +01:00
parent 17dbdc2757
commit 021d79d568
4 changed files with 9 additions and 5 deletions

View file

@ -1,4 +1,3 @@
use glam::Vec3;
use shipyard::{UniqueViewMut, UniqueView, View, IntoIter}; use shipyard::{UniqueViewMut, UniqueView, View, IntoIter};
use crate::{ use crate::{
player::MainPlayer, player::MainPlayer,

View file

@ -51,7 +51,6 @@ pub fn render_selection_box(
lookat: View<LookingAtBlock>, lookat: View<LookingAtBlock>,
camera: View<Camera>, camera: View<Camera>,
mut target: NonSendSync<UniqueViewMut<RenderTarget>>, mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
display: NonSendSync<UniqueView<Renderer>>,
program: NonSendSync<UniqueView<SelBoxShaderPrefab>>, program: NonSendSync<UniqueView<SelBoxShaderPrefab>>,
buffers: NonSendSync<UniqueView<SelectionBoxBuffers>>, buffers: NonSendSync<UniqueView<SelectionBoxBuffers>>,
) { ) {

View file

@ -85,6 +85,7 @@ impl ChunkMeshStorage {
} }
pub fn insert(&mut self, mesh: ChunkMesh) -> usize { pub fn insert(&mut self, mesh: ChunkMesh) -> usize {
let index = self.index; let index = self.index;
debug_assert!(self.meshes.get(&index).is_none());
self.meshes.insert_unique_unchecked(index, mesh); self.meshes.insert_unique_unchecked(index, mesh);
self.index += 1; self.index += 1;
index index

View file

@ -210,11 +210,16 @@ fn process_completed_tasks(
//apply the mesh //apply the mesh
let vertex_buffer = VertexBuffer::new(&renderer.display, &vertices).unwrap(); let vertex_buffer = VertexBuffer::new(&renderer.display, &vertices).unwrap();
let index_buffer = IndexBuffer::new(&renderer.display, PrimitiveType::TrianglesList, &indexes).unwrap(); let index_buffer = IndexBuffer::new(&renderer.display, PrimitiveType::TrianglesList, &indexes).unwrap();
let mesh_index = meshes.insert(ChunkMesh { let mesh = ChunkMesh {
vertex_buffer, vertex_buffer,
index_buffer, index_buffer,
}); };
chunk.mesh_index = Some(mesh_index); if let Some(index) = chunk.mesh_index {
meshes.update(index, mesh).expect("Mesh update failed");
} else {
let mesh_index = meshes.insert(mesh);
chunk.mesh_index = Some(mesh_index);
}
//update chunk state //update chunk state
chunk.current_state = CurrentChunkState::Rendered; chunk.current_state = CurrentChunkState::Rendered;