Skip to content

Removing MeshMaterial3d from entity panics. #18843

Closed
@Noxmore

Description

@Noxmore

Bevy version

0.16.0-rc.4

Relevant system information

AdapterInfo { name: "AMD Radeon RX 7900 XTX (RADV NAVI31)", vendor: 4098, device: 29772, device_type: DiscreteGpu, driver: "radv", driver_info: "Mesa 25.0.3-arch1.1", backend: Vulkan }

What you did

I removed a MeshMaterial3d<StandardMaterial> from an entity after the mesh visually appeared.

What went wrong

It panicked with the message

thread 'Compute Task Pool (22)' panicked at /home/nox/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_pbr-0.16.0-rc.4/src/material.rs:1014:79:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_pbr::material::specialize_material_meshes<bevy_pbr::pbr_material::StandardMaterial>`!

Additional information

Here is a minimal project to reproduce it.

use std::time::Duration;
use bevy::{prelude::*, time::common_conditions::on_timer};

fn main() {
	App::new()
		.add_plugins(DefaultPlugins)
		.add_systems(Startup, setup)
		// It seems to only panic when the mesh appears visually, this makes sure that happens
		.add_systems(Update, remove_materials.run_if(on_timer(Duration::from_secs(1))))
		.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
	commands.spawn((
		Mesh3d(asset_server.add(Cuboid::from_length(1.).into())),
		MeshMaterial3d(asset_server.add(StandardMaterial::default())),
	));

	commands.spawn((
		Camera3d::default(),
		Transform::from_translation(Vec3::splat(3.)).looking_at(Vec3::ZERO, Vec3::Y),
	));
}

fn remove_materials(
	mut commands: Commands,
	query: Query<Entity, With<MeshMaterial3d<StandardMaterial>>>,
) {
	for entity in &query {
		commands.entity(entity).remove::<MeshMaterial3d<StandardMaterial>>();
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions