Skip to content

App crashes on Windows when reading from a signal that was updated via use_drop in another window #4466

@AnteDeliria

Description

@AnteDeliria

Problem

When writing to a signal within use_drop from a child window, the application sometimes crashes if the same signal is read within the parent window.

Steps To Reproduce

Steps to reproduce the behavior:

  • Create a signal within the parent window
  • Pass it as a prop to the child window
  • Update the passed signal via use_drop within the child window (called when the child window is closed)
  • Read this signal within the parent window

The application crashes with the following error message:

Application [windows] exited with error: exit code: 0xc000041d

Reproducible example:

use dioxus::{core::use_drop, prelude::*};


fn main() {
    dioxus::launch(app);
}

fn app() -> Element {
    let window_open = use_signal(|| false);

    rsx! {
        div {
            button {
                onclick: move |_| {
                    dioxus::desktop::window().new_window(
                        VirtualDom::new_with_props(
                            NewWindow,
                            NewWindowProps {
                                window_open
                            }
                        ),
                        Default::default()
                    );
                },
                "New Window"
            }
        }

        // Reading from window_open after it has been written to
        // in another window with use_drop
        // sometimes causes a crash 
        div {
            if window_open() {
                "Window is open"
            } else {
                "Window is closed"
            }
        }
    }
}

#[component]
fn NewWindow(mut window_open: Signal<bool>) -> Element {
    window_open.set(true);
    use_drop(move || window_open.set(false));

    rsx! {
        div {
            h1 { "Popup Window" }
        }
    }
}

Expected behavior

The app doesn't crash

Screenshots

Image

Environment:

  • Dioxus version: 0.7.0-alpha.3-main
  • Rust version: 1.90.0-nightly
  • OS info: Windows 10, 10.0.19045 Build 19045
  • App platform: desktop

Questionnaire

This crash is inconsistent - sometimes the window closes fine, other times the app crashes. Maybe this is due to a race condition or something. The crash doesn't seem to happen if the signal is never read in the parent window at least.

I have narrowed down the commits that might be causing this:

The last working version was eccd75a (#3602)
After that, several commits don't compile at all:
87d113b (#3533)
bcd34e9 (#3801)
8dbb652 (#3560)
7c2cea9 (#3802)
91a2180 (#3810)
This bug first appears in the subsequent working commit 650605f.

I suspect that 91a2180 (#3810) is responsible for this bug, as it changes files related to wry.

As a side note, I understand that cross-dom signals in Dioxus aren't exactly a standardized thing, but they seem to work fine and respond accordingly if updated between windows. The bug described here is the only thing that isn't working. I only tested this on Windows, not sure if this is an issue on other OS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions