Skip to content

Commit

Permalink
Fix Box<dyn Reflect> struct with a hashmap in it panicking when clone…
Browse files Browse the repository at this point in the history
…_value is called on it (bevyengine#8184)

# Objective

- Fix the issue described in bevyengine#8183: Box<dyn Reflect> structs with a
hashmap in them will panic when clone_value is called on it
- Fixes: bevyengine#8183

## Solution

- Updates the implementation of Reflect for Hashmaps to make clone_value
call from_reflect on the key before inserting it into the new struct
  • Loading branch information
NoahShomette authored Apr 22, 2023
1 parent 37ad73d commit a9f766c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ macro_rules! impl_reflect_for_hashmap {
let mut dynamic_map = DynamicMap::default();
dynamic_map.set_name(self.type_name().to_string());
for (k, v) in self {
dynamic_map.insert_boxed(k.clone_value(), v.clone_value());
let key = K::from_reflect(k).unwrap_or_else(|| {
panic!("Attempted to clone invalid key of type {}.", k.type_name())
});
dynamic_map.insert_boxed(Box::new(key), v.clone_value());
}
dynamic_map
}
Expand Down

0 comments on commit a9f766c

Please sign in to comment.