Maybe make FWS a bit safer.

This commit is contained in:
IQuant 2024-09-28 23:14:05 +03:00
parent 5d7792a2e4
commit 279825fd7c

View file

@ -118,8 +118,8 @@ impl ParticleWorldState {
mat_id mat_id
} }
fn get_cell_type(&self, cell: &ntypes::Cell) -> ntypes::CellType { fn get_cell_type(&self, cell: &ntypes::Cell) -> Option<ntypes::CellType> {
unsafe { cell.material_ptr().as_ref().unwrap().cell_type } unsafe { Some(cell.material_ptr().as_ref()?.cell_type) }
} }
pub(crate) unsafe fn encode_area( pub(crate) unsafe fn encode_area(
@ -144,7 +144,7 @@ impl ParticleWorldState {
}; };
let cell = self.get_cell_raw(x, y); let cell = self.get_cell_raw(x, y);
if let Some(cell) = cell { if let Some(cell) = cell {
let cell_type = self.get_cell_type(cell); let cell_type = self.get_cell_type(cell).unwrap_or(ntypes::CellType::None);
match cell_type { match cell_type {
ntypes::CellType::None => {} ntypes::CellType::None => {}
// Nobody knows how box2d pixels work. // Nobody knows how box2d pixels work.
@ -158,7 +158,7 @@ impl ParticleWorldState {
raw_pixel.material = self.get_cell_material_id(cell); raw_pixel.material = self.get_cell_material_id(cell);
} }
// ??? // ???
ntypes::CellType::Invalid => {} _ => {}
} }
} }
self.runner.put_pixel(raw_pixel); self.runner.put_pixel(raw_pixel);