Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGL: INVALID_OPERATION drawArrays with repo #5732

Closed
AlexOkafor opened this issue Aug 18, 2022 · 5 comments
Closed

WebGL: INVALID_OPERATION drawArrays with repo #5732

AlexOkafor opened this issue Aug 18, 2022 · 5 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds

Comments

@AlexOkafor
Copy link
Contributor

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

@AlexOkafor AlexOkafor added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 18, 2022
@rparrett rparrett added A-Rendering Drawing game state to the screen O-Web Specific to web (WASM) builds and removed S-Needs-Triage This issue needs to be labelled labels Aug 18, 2022
@Azorlogh
Copy link
Contributor

Azorlogh commented Jan 2, 2023

I've met this issue as well, here is some more detail:

The rendering completely stops (canvas turns fully transparent in firefox, and freezes in chromium)
BUT the systems still seem to be running normally

Here is the updated minimal example for latest bevy 0.9

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(Camera2dBundle {
    ..Default::default()
  });

  cmd.spawn((
    Ticker {
      timer: Timer::new(Duration::from_secs(5), TimerMode::Repeating),
    },
    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();
    }
  }
}

System info: AdapterInfo { name: "NVIDIA GeForce GTX 980/PCIe/SSE2", vendor: 4318, device: 0, device_type: Other, driver: "", driver_info: "", backend: Gl }

@jabuwu
Copy link
Contributor

jabuwu commented Apr 7, 2023

This is still an issue in 0.10 and I just ran into a case where setting Visibility::Hidden on a mesh's parent entity can cause this too.

@Azorlogh
Copy link
Contributor

Azorlogh commented Apr 26, 2023

This issue should be fixed as of #8446 🙂

@jabuwu
Copy link
Contributor

jabuwu commented Apr 26, 2023

This issue should be fixed as of #8446 🙂

That's great news! I have 3-4 projects plagued by this bug so I'll give that a try and report back soon!

@jabuwu
Copy link
Contributor

jabuwu commented Apr 27, 2023

Can confirm this is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds
Projects
None yet
Development

No branches or pull requests

5 participants