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

Bizarre Stack Overflow when utilizing Default trait or ..default() to initialize components #12820

Closed
jaydevelopsstuff opened this issue Apr 1, 2024 · 1 comment
Labels
A-Utils Utility functions and types C-Bug An unexpected or incorrect behavior S-User-Error This issue was caused by a mistake in the user's approach

Comments

@jaydevelopsstuff
Copy link

Bevy version

0.13.1

Relevant system information

  • Rust version 1.77.1 (from cargo --version)
  • M1 Macbook Air MacOS Sonoma 14.0 (23A344)

What you did

In my own project I was trying to create a Component that implemented the Default trait for my own purposes and ran into a stack overflow when spawning an entity bundle with the component. There was no real distinguishable cause.

After commenting out some code I found it had to with implementing and using the Default trait on one of my own Components. This looked like it could be an issue with Bevy so I created an MRE using just MinimalPlugins, so headless Bevy and low and behold the stack overflow persists.

What went wrong

I'd expect initializing via the Default trait or using ..default(), to well, not cause any issues and work as you'd expect the Default trait to work. But instead it resulted in a stack overflow error. These overflows seem to originate from compute task pool threads based on the resulting errors.

This does not seem to be related to GUI at all as it still occurs with only MinimalPlugins.

Additional information

MRE Repo

Possibly related issue: #8406

The only workaround I've found is just to straight-up not use the Default trait or ..default() to initialize in-house Components when creating an entity.

Also just for clarity, when I say in-house I mean anything not in Bevy's codebase.

@jaydevelopsstuff jaydevelopsstuff added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 1, 2024
@james7132 james7132 added A-Utils Utility functions and types S-User-Error This issue was caused by a mistake in the user's approach and removed S-Needs-Triage This issue needs to be labelled labels Apr 1, 2024
@james7132
Copy link
Member

This seems to be caused by the fact that default calls Default::default, which will recursively called until the the stack overflows. See #8879. Closing this out as a user error since we already have an issue about silencing the warning.

@james7132 james7132 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Utils Utility functions and types C-Bug An unexpected or incorrect behavior S-User-Error This issue was caused by a mistake in the user's approach
Projects
None yet
Development

No branches or pull requests

2 participants