bevyengine / bevyengine/bevy

Removing an Entity consisting of a Camera and ContrastAdaptiveSharpening in a conditional system causes crash

Open
#18,896 1 comment 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug I-Crash S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.15.3

## Relevant system information

```
AdapterInfo { name: "Apple M2 Pro", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
```

## What you did

Attempted to remove an entity consisting of a Camera and a ContrastAdaptiveSharpening component

```rust
mod render;

use bevy::{
core_pipeline::{
contrast_adaptive_sharpening::ContrastAdaptiveSharpening,
fxaa::{Fxaa, Sensitivity},
},
input::common_conditions::input_just_released,
pbr::ShadowFilteringMethod,
prelude::*,
window::{PresentMode, WindowResolution},
};

fn main() {
App::new()
.add_plugins((DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Camera Removal Test".into(),
present_mode: PresentMode::AutoNoVsync,
resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0),
..default()
}),
..default()
}),))
.add_systems(Startup, setup)
.add_systems(Update, update.run_if(input_just_released(KeyCode::KeyK)))
.run();
}

pub const CAS: ContrastAdaptiveSharpening = ContrastAdaptiveSharpening {
enabled: true,
sharpening_strength: 0.6, // bevy recommended default
denoise: false,
};

pub const MSAA: Msaa = Msaa::Sample4;
pub const SHADOW_FILTERING: ShadowFilteringMethod = ShadowFilteringMethod::Gaussian;
pub const FXAA: Fxaa = Fxaa {
enabled: true,
edge_threshold: Sensitivity::High,
edge_threshold_min: Sensitivity::High,
};

fn setup(mut commands: Commands) {
commands.spawn((
Camera3d::default(),
Msaa::Sample4,
Fxaa {
enabled: true,
edge_threshold: Sensitivity::High,
edge_threshold_min: Sensitivity::High,
},
ContrastAdaptiveSharpening::default(),
));
}

fn update(mut commands: Commands, entities: Query>) {
if !entities.is_empty() {
commands.entity(entities.single()).despawn();
}
}
```

In this example, the `run_if` condition is based upon a key event, but this also occurs using an `Event`

## What went wrong

The application crashes after the `update` system is run.

## Additional information

After crashing the following log output is produced:

```bash
bevy_core_pipeline-0.15.3/src/contrast_adaptive_sharpening/mod.rs:253:18:
Attempting to create an EntityCommands for entity 3v1#4294967299, which doesn't exist.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_core_pipeline::contrast_adaptive_sharpening::prepare_cas_pipelines`!
2025-04-22T02:46:16.512081Z WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply?

```

My hunch is that the `prepare_cas_pipelines` system is looping over a list of removals (`RemovedComponents`) and performing `commands.entity(entity).remove::()`. The entity in question has already been removed in the main world, hence the `Attempting to create an EntityCommands for entity 3v1#4294967299, which doesn't exist`. Link to source: https://github.com/bevyengine/bevy/blob/main/crates/bevy_anti_aliasing/src/contrast_adaptive_sharpening/mod.rs#L238

should this be replaced with `get_entity` instead of `entity`? Or is there something inherently wrong with the logic of the example?

Appreciate any assistance!

Contributor guide

Open the contributing guide

Research direction

Start with crates/bevy_anti_aliasing/src/contrast_adaptive_sharpening/mod.rs, especially prepare_cas_pipelines and its RemovedComponents handling. Reproduce the supplied Bevy 0.15.3 camera-removal example, including removal triggered by a key event or Event. Done means removing the camera with ContrastAdaptiveSharpening no longer panics or leaves queued commands.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.