AnyMap: print deserialization errors to stderr
This commit is contained in:
parent
f59abd9684
commit
1537171205
1 changed files with 21 additions and 4 deletions
|
@ -120,7 +120,7 @@ impl AnyMapElement {
|
|||
match self {
|
||||
AnyMapElement(Deserialized { value, .. }) => value.downcast_mut(),
|
||||
AnyMapElement(Serialized(s, _)) => {
|
||||
*self = Self::new(ron::from_str::<T>(s).ok()?);
|
||||
*self = Self::new(from_ron_str::<T>(s)?);
|
||||
|
||||
match self {
|
||||
AnyMapElement(Deserialized { value, .. }) => value.downcast_mut(),
|
||||
|
@ -138,12 +138,14 @@ impl AnyMapElement {
|
|||
Deserialized { value, .. } => {
|
||||
if !value.is::<T>() {
|
||||
*self = Self::new(set_with());
|
||||
// TODO: log this error, because it can occurs when user used same Id or same type for different widgets
|
||||
eprintln!(
|
||||
"egui: Value stored in serialized memory was not of type {}",
|
||||
std::any::type_name::<T>()
|
||||
);
|
||||
}
|
||||
}
|
||||
Serialized(s, _) => {
|
||||
*self = Self::new(ron::from_str::<T>(s).unwrap_or_else(|_| set_with()));
|
||||
// TODO: log deserialization error
|
||||
*self = Self::new(from_ron_str::<T>(s).unwrap_or_else(|| set_with()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,3 +155,18 @@ impl AnyMapElement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_ron_str<T: serde::de::DeserializeOwned>(ron: &str) -> Option<T> {
|
||||
match ron::from_str::<T>(ron) {
|
||||
Ok(value) => Some(value),
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"egui: Failed to deserialize {} from memory: {}, ron: {:?}",
|
||||
std::any::type_name::<T>(),
|
||||
err,
|
||||
ron
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue