Skip to content

Spawning an Empty mesh results in "Use-after-free" error message #24874

Description

@Amatsugu

Bevy version and features

Bevy 0.19.0, default features.

What you did

Create a new Mesh without adding any vertices/indices etc. and spawned an entity using that mesh.

What went wrong

After spawning the entity the following error is logged:

ERROR bevy_render::slab_allocator: Use-after-free: attempted to copy element data for an unallocated key

The error message does not match what is actually happening and results in confusion.

Perhaps a warning or error sooner in the process the points to mesh being empty, assuming empty meshes are not a supported feature.

Steps to reproduce

Add this system to the startup schedule:

fn test(mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>, mut commands: Commands)
{
	let m = Mesh::new(
		bevy::mesh::PrimitiveTopology::TriangleList,
		RenderAssetUsages::RENDER_WORLD,
	);
	let handle = meshes.add(m);
	commands.spawn((
		Mesh3d(handle),
		MeshMaterial3d(materials.add(Color::WHITE)),
		Transform::default(),
	));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-BugAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Needs SME Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions