mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
AnyMap: print deserialization errors to stderr
This commit is contained in:
@@ -120,7 +120,7 @@ impl AnyMapElement {
|
|||||||
match self {
|
match self {
|
||||||
AnyMapElement(Deserialized { value, .. }) => value.downcast_mut(),
|
AnyMapElement(Deserialized { value, .. }) => value.downcast_mut(),
|
||||||
AnyMapElement(Serialized(s, _)) => {
|
AnyMapElement(Serialized(s, _)) => {
|
||||||
*self = Self::new(ron::from_str::<T>(s).ok()?);
|
*self = Self::new(from_ron_str::<T>(s)?);
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
AnyMapElement(Deserialized { value, .. }) => value.downcast_mut(),
|
AnyMapElement(Deserialized { value, .. }) => value.downcast_mut(),
|
||||||
@@ -138,12 +138,14 @@ impl AnyMapElement {
|
|||||||
Deserialized { value, .. } => {
|
Deserialized { value, .. } => {
|
||||||
if !value.is::<T>() {
|
if !value.is::<T>() {
|
||||||
*self = Self::new(set_with());
|
*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, _) => {
|
Serialized(s, _) => {
|
||||||
*self = Self::new(ron::from_str::<T>(s).unwrap_or_else(|_| set_with()));
|
*self = Self::new(from_ron_str::<T>(s).unwrap_or_else(|| set_with()));
|
||||||
// TODO: log deserialization error
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user