Fix crash of the online editor

Component's get_item_ref has a life time attached to it, and in the
interpreter we're having two vtable implementations, one for
ErasedComponentBox and another generated one. The approach with
as_pin_ref to transfer the lifetime to a reference to the trait object
for the other vtable isn't working because as_pin_ref consumes the VRef
and then takes the address of a temporary on the stack.

Short of a cleaner solution, this patch circumvents the second vtable
indirection and calls our extern "C" function directly.
This commit is contained in:
Simon Hausmann 2020-11-12 14:22:22 +01:00
parent 3c79488637
commit 79bfa080c6
2 changed files with 4 additions and 15 deletions

View file

@ -224,7 +224,10 @@ impl Component for ErasedComponentBox {
self.borrow().as_ref().apply_layout(r)
}
fn get_item_ref<'a>(self: Pin<&'a Self>, index: usize) -> Pin<ItemRef<'a>> {
vtable::VRef::as_pin_ref(self.get_ref().borrow()).get_item_ref(index)
// We're having difficulties transferring the lifetime to a pinned reference
// to the other ComponentVTable with the same life time. So skip the vtable
// indirection and call our implementation directly.
unsafe { get_item_ref(self.get_ref().borrow(), index) }
}
}