Skip to content

Commit

Permalink
Only attempt to copy resources that still exist from scenes (bevyengi…
Browse files Browse the repository at this point in the history
…ne#9984)

# Objective

Avert a panic when removing resources from Scenes.

### Reproduction Steps
```rust
let mut scene = Scene::new(World::default());
scene.world.init_resource::<Time>();
scene.world.remove_resource::<Time>();
scene.clone_with(&app.resource::<AppTypeRegistry>());
```

### Panic Message
```
thread 'Compute Task Pool (10)' panicked at 'Requested resource bevy_time::time::Time does not exist in the `World`. 
                Did you forget to add it using `app.insert_resource` / `app.init_resource`? 
                Resources are also implicitly added via `app.add_event`,
                and can be added by plugins.', .../bevy/crates/bevy_ecs/src/reflect/resource.rs:203:52

```

## Solution

Check that the resource actually still exists before copying.

---

## Changelog

- resolved a panic caused by removing resources from scenes
  • Loading branch information
ricky26 authored and Ray Redondo committed Jan 9, 2024
1 parent 09c7927 commit 25964bd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/bevy_scene/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ impl Scene {
let type_registry = type_registry.read();

// Resources archetype
for (component_id, _) in self.world.storages().resources.iter() {
for (component_id, resource_data) in self.world.storages().resources.iter() {
if !resource_data.is_present() {
continue;
}

let component_info = self
.world
.components()
Expand Down

0 comments on commit 25964bd

Please sign in to comment.