Open lucatrv opened 2 years ago
Hi, thanks or the report. I tested it on macos initially and can confirm that it still works there. I'll give it a try with Linux.
Yeah on Ubuntu I get a crash, too. Seems that the issue is in iced_native::user_interface::UserInterface::update
, the reload might mess with the data that gets ManuallyDrop
ed there. I'll take a look over the holidays if this can be solved with either a custom command or a manual run loop.
Sorry, didn't get enough time to fix this. Happy to accept contributions.
Not quite sure why this works in macos but not under Windows/Linux.
The issue manifests as a segmentation fault when dealing with the root and overlay Element
s at UserInterface::update when wrapping those with a ManuallyDrop
. I think the ManuallyDrop
isn't the root cause, something about the rendering state might become invalid through the reload.
For now I'll add a note to the example and maybe someone with deeper knowledge of iced than me can look at this?!
Hi, I investigated this a bit.
Here is what happens:
view
(in the dynamically loaded lib) returns a Element<Message>
(internally this is a Widget
trait object).Application::run
will call Application::view
and then hold onto the returned Element<Message>
for a while (e.g. view is only called again when it determines that the interface is outdated, see the calls to build_user_interface
in https://github.com/iced-rs/iced/blob/0.5/winit/src/application.rs#L235).UserInterface::update
runs it will use this element without necessarily calling view
again.Element<Message>
will contain a vtable pointer pointing into old unloaded version.UserInterface::update
it tries to call the overlay
method on the trait object, this tries to read the unloaded vtable and segfaults.Potential solutions:
hot-lib-reloader
to offer an option to not unload old versions. The only downside (afaik) is leaking the lib when you need to reload but that seems worth it to have hotreloading work.
// e.g. add this in the view method in the dynamic lib
thread_local! {
static KEEP_LOADED: Box<u8> = Box::new(0);
}
KEEP_LOADED.with(|_| {}); // initialize
(note: this is all on the iced version used above (0.5.2
) so some details could have changed)
(edit: I would guess that there might already be something preventing the lib from being unloaded on macos, but I can't test that myself)
Thanks! Gonna take a look at this soon.
I've been experimenting with the following
Iced
sample code, but it keeps crashing at everylib
reload. I can't figure out if I'm mistaking something or if it's due to ahot-lib-reloader-rs
' issue, can you please help me out?I tested the attached code both on Windows 10 and Arch Linux, with
rustc
version1.65.0
and1.67.0-nightly
, and I attempted also usingcargo run --features iced/glow
with no luck.bin
lib