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

Panic: "component already borrowed" when using Mut with for-each systems #294

Closed
zerovolts opened this issue Aug 22, 2020 · 0 comments · Fixed by #383
Closed

Panic: "component already borrowed" when using Mut with for-each systems #294

zerovolts opened this issue Aug 22, 2020 · 0 comments · Fixed by #383
Labels
A-ECS Entities, components, systems, and events P-Crash A sudden unexpected crash

Comments

@zerovolts
Copy link

zerovolts commented Aug 22, 2020

Bevy panics when spawning entities inside a system with a component that is used in multiple other for-each systems, where at least one of the systems takes a Mut version of the component.

The problem statement is very specific, but doing any of these fixes the issue:

  • Changing either or both of the systems that take Velocity into Query systems.
  • Removing either of the systems that use Velocity.
  • Changing acceleration_system to take a non-Mut reference.
  • Spawning the projectile entities in a startup system instead.
  • Spawning a single projectile entity in setup alongside the emitter? 🤷‍♂️

Minimal Repro

use bevy::prelude::*;

fn main() {
    App::build()
        .add_default_plugins()
        .add_startup_system(setup.system())
        .add_system(velocity_system.system())
        .add_system(acceleration_system.system())
        .add_system(emitter_system.system())
        .run();
}

struct Emitter;
struct Velocity;
struct Acceleration;

fn setup(mut commands: Commands) {
    commands.spawn((Emitter,));
}

fn velocity_system(velocity: &Velocity) { }

fn acceleration_system(mut velocity: Mut<Velocity>) { }

fn emitter_system(mut commands: Commands, emitter: &Emitter) {
    commands.spawn((Velocity, Acceleration));
}

Error

thread '<unnamed>' panicked at 'bevy_borrow_test::Velocity already borrowed', C:\Users\zach\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\src\libcore\macros\mod.rs:16:9

Minimal repro project containing full error: https://github.com/zerovolts/bevy-borrow-panic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events P-Crash A sudden unexpected crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants