Skip to content

Commit

Permalink
settings.rs: fix document reborrow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Mar 20, 2023
1 parent 2b3186c commit 0bd8f5d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ impl SettingsInner {
};
document[&type_name][prop.name()] = new_val;

/* Update other objects of the same type
* Do not call set_property without dropping `document` first since it's borrowed mutably. */
drop(document);

for e in self
.entries
.borrow()
Expand All @@ -222,14 +226,20 @@ impl SettingsInner {
.filter(|wref| wref.upgrade().as_ref() != Some(obj))
{
let Some(obj) = e.upgrade() else { continue; };
let document = self.document.borrow();
macro_rules! set_if_neq {
($ty:ty, $val:expr) => {{
if obj.property::<$ty>(prop.name()) != $val {
obj.set_property(prop.name(), $val);
let val = { $val };
// set_property might notify recursively read_settings which will ask to borrow
// document mutably, so drop this here.
drop(document);
if obj.property::<$ty>(prop.name()) != val {
obj.set_property(prop.name(), val);
}
}};
($ty:ty, opt $val:expr) => {{
if let Some(val) = $val {
let val = { $val };
if let Some(val) = val {
set_if_neq!($ty, val);
}
}};
Expand Down

0 comments on commit 0bd8f5d

Please sign in to comment.