DioxusLabs / DioxusLabs/dioxus

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

Open
#4,466 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**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) -> 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](https://github.com/user-attachments/assets/b9d83819-f034-45cc-920b-f8d7b29dc92f)

**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 eccd75a1fe345516398467360eec849ba67f1672 (#3602)
After that, several commits don't compile at all:
87d113bddd041bf3b5d9d8dfdcbb0a8b41822ffa (#3533)
bcd34e9a9867789deece29472077db0c7e05cc78 (#3801)
8dbb6526286f6449b85a194229c64858057c7eb5 (#3560)
7c2cea9df7dea6df445388798043a3f4e30bfd38 (#3802)
91a218039e81e7c88c5ed76c0b8b616dc8177162 (#3810)
This bug first appears in the subsequent working commit 650605f4d14d3b9e006f645e95109e21f1ff63da.

I suspect that 91a218039e81e7c88c5ed76c0b8b616dc8177162 (#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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.