Skip to content

WebGL: INVALID_OPERATION drawArrays with repo #5732

@AlexOkafor

Description

@AlexOkafor

Bevy version

0.8.0

Relevant system information

  • WASM builds
`AdapterInfo { name: "ANGLE (NVIDIA, NVIDIA GeForce GTX 1080 Ti Direct3D11 vs_5_0 ps_5_0, D3D11)", vendor: 4318, device: 0, device_type: Other, backend: Gl }}`

What you did

Creating a color material and/or mesh then removing the entity that is rendering it triggers an error in the console.

The minimal repo case is located here for easy cloning + running via trunk: https://github.com/AlexOkafor/bevy_webgl_invalid_op_repo
Relevant code below:

use std::time::Duration;

use bevy::{prelude::*, sprite::MaterialMesh2dBundle};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(update_ticker)
        .run();
}

#[derive(Component)]
struct Ticker {
    timer: Timer,
}

fn setup(
    mut cmd: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    // This is needed otherwise the invalid operation will not fire.
    cmd.spawn_bundle(Camera2dBundle {
        ..Default::default()
    });

    cmd.spawn()
        .insert(Ticker {
            timer: Timer::new(Duration::from_secs(5), false),
        })
        .insert_bundle(MaterialMesh2dBundle {
            mesh: meshes.add(shape::Quad::default().into()).into(),
            material: materials.add(ColorMaterial::from(Color::WHITE)),
            transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
            ..Default::default()
        });
}

// delete the entity after 5 seconds.
fn update_ticker(mut cmd: Commands, time: Res<Time>, mut q: Query<(Entity, &mut Ticker)>) {
    for (e, mut t) in q.iter_mut() {
        t.timer.tick(time.delta());
        if t.timer.just_finished() {
            cmd.entity(e).despawn();
        }
    }
}

What went wrong

when the same code is run natively, there doesn't seem to be any errors coming to the console.

Additional information

image
logs: 127.0.0.1-1660842111571.log

  • currently, workarounds are to make sure either:
    1. don't delete the entities
    2. keep an entity with that material/mesh in the scene off camera

discord discussion: https://discord.com/channels/691052431525675048/1008708052519755916

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorO-WebSpecific to web (WASM) builds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions