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

Rendering crash in wasm after switching between different pipelines #7072

Closed
Azorlogh opened this issue Jan 2, 2023 · 1 comment
Closed
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled

Comments

@Azorlogh
Copy link
Contributor

Azorlogh commented Jan 2, 2023

Bevy version

0.9.1

Relevant system information

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

What you did

The following is a minimal reproducible example using bevy_prototype_lyon:

use bevy::{
  prelude::*,
  render::{mesh::Indices, render_resource::PrimitiveTopology},
};
use bevy_prototype_lyon::prelude::*;

fn main() {
  App::new()
    .add_plugins(DefaultPlugins)
    .add_plugin(ShapePlugin)
    .add_startup_system(setup_system)
    .add_system(switch_mode)
    .run();
}

fn switch_mode(
  mut commands: Commands,
  keys: Res<Input<KeyCode>>,
  q_cam: Query<(Entity, Option<&Camera2d>), With<Camera>>,
  q_obj: Query<Entity, With<Handle<Mesh>>>,
) {
  if keys.just_pressed(KeyCode::Return) {
    let (e, cam_2d) = q_cam.single();
    commands.entity(e).despawn_recursive();
    if cam_2d.is_some() {
      commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-20.0, 20.5, 50.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
      });
    } else {
      commands.spawn(Camera2dBundle::default());
    }
  }

  if keys.just_pressed(KeyCode::Space) {
    for e in q_obj.iter().skip(1) {
      commands.entity(e).despawn_recursive();
    }
  }
}

fn setup_system(
  mut commands: Commands,
  mut meshes: ResMut<Assets<Mesh>>,
  mut materials: ResMut<Assets<StandardMaterial>>,
) {
  let mut make_mesh = || {
    let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
    mesh.set_indices(Some(Indices::U32(vec![0, 1, 2, 2, 1, 3])));
    mesh.insert_attribute(
      Mesh::ATTRIBUTE_POSITION,
      vec![
        [0.0, 0.0, 3.0],
        [2.0, 0.0, 3.0],
        [0.0, 2.0, 3.0],
        [2.0, 2.0, 3.0],
      ],
    );
    mesh.insert_attribute(
      Mesh::ATTRIBUTE_NORMAL,
      vec![
        [0.0, 0.0, 1.0],
        [0.0, 0.0, 1.0],
        [0.0, 0.0, 1.0],
        [0.0, 0.0, 1.0],
      ],
    );
    mesh.insert_attribute(
      Mesh::ATTRIBUTE_UV_0,
      vec![[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]],
    );
    meshes.add(mesh)
  };

  commands.spawn(Camera2dBundle::default());
  for i in [-1.0, 0.0, 1.0] {
    commands.spawn((
      GeometryBuilder::build_as(
        &shapes::RegularPolygon {
          sides: 6,
          feature: shapes::RegularPolygonFeature::Radius(4.0),
          ..shapes::RegularPolygon::default()
        },
        DrawMode::Outlined {
          fill_mode: FillMode::color(Color::CYAN),
          outline_mode: StrokeMode::new(Color::BLACK, 1.0),
        },
        Transform::from_xyz(i * 100.0, 0.0, 0.0),
      ),
      make_mesh(),
      materials.add(Color::rgb(1.0, 1.0, 1.0).into()),
    ));
  }
}

What went wrong

In firefox, the result is a blank screen.
In chromium, the result is a rendering freeze.
In both, my game's systems are still running normally, only the rendering is affected.

Additional information

Upon the crash, chromium reports the following warning 1 time: WebGL: INVALID_OPERATION: drawArrays: no buffer is bound to enabled attribute

@Azorlogh Azorlogh added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 2, 2023
@Azorlogh
Copy link
Contributor Author

Azorlogh commented Jan 2, 2023

I think this is actually a duplicate of #5732

@Azorlogh Azorlogh closed this as completed Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled
Projects
None yet
Development

No branches or pull requests

1 participant