Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing struct as a prop leads to panic / allocation error #1390

Closed
1 of 3 tasks
raffomania opened this issue Aug 22, 2023 · 2 comments
Closed
1 of 3 tasks

Passing struct as a prop leads to panic / allocation error #1390

raffomania opened this issue Aug 22, 2023 · 2 comments

Comments

@raffomania
Copy link

Problem

The following example leads to a panic during runtime:

fn App(cx: Scope) -> Element {
    let song = Song {
        artist: "Artist".to_string(),
        title: "Title".to_string(),
    };
    debug!("{song:?}");

    render! {
        div { Child { song: &song } }
    }
}

#[derive(Debug)]
struct Song {
    artist: String,
    title: String,
}

#[inline_props]
fn Child<'a>(cx: Scope, song: &'a Song) -> Element {
    let Song { title, .. } = song;
    render! {"{title}"}
}

The error when running dx serve:

Dioxus @ v0.1.5 [18:41:54]


	> Profile : Debug
	> Hot Reload : Normal
	> Index Template : Default
	> URL Rewrite [index_on_404] : False

	> Build Time Use : 0 millis

[WARN] There were 1 warning messages during the build.
[DEBUG] dioxus_play - Song { artist: "Artist", title: "Title" }
thread 'main' panicked at 'encountered allocation error: Layout { size: 140728548278936, align: 1 (1 << 0) }', /home/rafael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bumpalo-3.13.0/src/alloc.rs:30:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[ERROR] dioxus_core::any_props - Error while rendering component `Child`: Any { .. }

Steps To Reproduce

I've created a minimal reproduction repo that runs into the error on my machine:

git clone git@github.com:raffomania/dioxus-allocation-error-repro.git
cd dioxus-allocation-error-repro
dx serve

Expected behavior

I'm expecting the code not to crash, or not to compile if it does something wrong.

Environment:

  • Dioxus version: 0.4.0
  • Rust version: 1.71.1
  • OS info: Arch Linux
  • App platform: desktop

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@raffomania
Copy link
Author

Moving to an explicit prop struct with #[derive(Props)] doesn't fix the error.

@ealmloff
Copy link
Member

This is the same issue as #1341. #1345 will fix this. Closing as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants