prevent panic when mask property is incorrect
use crate::material::PropertyValue;
+use crate::utils::log::{Log, MessageKind};
use crate::{
core::{algebra::Matrix4, arrayvec::ArrayVec, pool::Handle, scope_profile},
material::Material,
@@ -125,15 +126,14 @@ impl BatchStorage {
let data_key = &*data as *const _ as u64;
let mut material = (*layer.material.lock().unwrap()).clone();
- material
- .set_property(
+ match material.set_property(
&layer.mask_property_name,
PropertyValue::Sampler {
value: Some(layer.chunk_masks[chunk_index].clone()),
fallback: Default::default(),
},
- )
- .unwrap();
+ ) {
+ Ok(_) => {
let material = Arc::new(Mutex::new(material));
let mut hasher = DefaultHasher::new();
@@ -143,7 +143,8 @@ impl BatchStorage {
let key = hasher.finish();
- let batch = if let Some(&batch_index) = self.batch_map.get(&key) {
+ let batch = if let Some(&batch_index) = self.batch_map.get(&key)
+ {
self.batches.get_mut(batch_index).unwrap()
} else {
self.batch_map.insert(key, self.batches.len());
@@ -169,6 +170,16 @@ impl BatchStorage {
depth_offset: terrain.depth_offset_factor(),
});
}
+ Err(e) => Log::writeln(
+ MessageKind::Error,
+ format!(
+ "Failed to prepare batch for terrain chunk.\
+ Unable to set mask texture for terrain material. Reason: {:?}",
+ e
+ ),
+ ),
+ }
+ }
}
}
_ => (),
