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

Adding a PointLight crashes the app #16

Closed
IceSentry opened this issue Feb 20, 2022 · 6 comments
Closed

Adding a PointLight crashes the app #16

IceSentry opened this issue Feb 20, 2022 · 6 comments

Comments

@IceSentry
Copy link
Contributor

IceSentry commented Feb 20, 2022

When I try to use this plugin with a scene with a point light it crashes.

For example, if I add a point light in the 3d example of this repo I get this error:

2022-02-20T18:57:30.397787Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 2, Vulkan)>`
    In a draw command, indexed:false indirect:false
      note: render pipeline = `shadow_pipeline`
    vertex 6 extends beyond limit 5 imposed by the buffer in slot 0. Did you bind the correct `Vertex` step-rate vertex buffer?

I don't get this error if I don't spawn a point light.

I tried it with bevy 0.6 and the latest bevy main and the bevy-main branch of this repo. This is on windows 10.

@IceSentry
Copy link
Contributor Author

I also tried it with the DX12 backend and I get the same error

@Toqozz
Copy link
Owner

Toqozz commented Feb 22, 2022

Can you see if this is still happening with 0.6.0?

I made a fair few changes before getting to this and I never reproduced.

Here's how I'm adding a point light in the 3d example to try to reproduce:

fn setup(mut commands: Commands, mut lines: ResMut<DebugLines>) {
    commands.spawn_bundle(PerspectiveCameraBundle {
        transform: Transform::from_translation(Vec3::new(0.0, 0.0, 5.0)),
        ..Default::default()
    });
    commands.spawn_bundle(PointLightBundle {
       ..Default::default() 
    });
    // A line that stays on screen 9 seconds
    lines.line_gradient(
        Vec3::new(1.0, -1.0, -1.0),
        Vec3::new(-1.0, 1.0, 1.0),
        9.0,
        Color::CYAN,
        Color::MIDNIGHT_BLUE,
    );
}

@IceSentry
Copy link
Contributor Author

So, I just tried it with 0.6.0 and I still get the same crash, but I noticed it only crashes when shadows are enabled on the point light. If shadows are not enabled it doesn't crash.

Here's how I was spawning it.

    commands.spawn_bundle(PointLightBundle {
        point_light: PointLight {
            intensity: 1500.0,
            shadows_enabled: true, // This seems to be the issue
            ..Default::default()
        },
        transform: Transform::from_xyz(4.0, 8.0, 4.0),
        ..Default::default()
    });

Toqozz added a commit that referenced this issue Feb 22, 2022
@Toqozz
Copy link
Owner

Toqozz commented Feb 22, 2022

So I've just disabled shadows (we shouldn't be casting/receiving shadows anyway) in 0.6.1, which seems to fix this, but still will have a look into what causes it.

@IceSentry
Copy link
Contributor Author

I just tried 0.6.1 with shadows on the point light and I can confirm it works.

@Toqozz
Copy link
Owner

Toqozz commented Feb 22, 2022

I think this is related to bevyengine/bevy#3959, where meshes with custom attributes seem to potentially get screwed up if they don't have an index buffer (and even then sometimes). If I add mesh indices then it doesn't crash with shadows enabled.

I won't close this for now since it might be the cause of other random issues if they come up.

Relevant thread from Discord:

[1:52 AM] thebracket: Adding an index buffer fixed the crash. I guess non-indexed buffers aren't a good idea now.
[2:00 AM] François 🥷🏻: I think they should be? bevyengine/bevy#3415
is the Bevy version you're using with this PR?
[2:00 AM] thebracket: Looks like the PR is pulling head from main, so it should be in there.
[2:03 AM] thebracket: I'll try and make a self-contained example, it's tied into a lot of other code. That'll probably help find the issue (with an index buffer, it's faster anyway - but it seems like that should have worked)
[2:04 AM] Gibonus 🙈: Yeah, as the author of the PR, I can't say I didn't overlook anything
[2:28 AM] thebracket: Interestingly, when I copied over the code into a self-contained example it worked. So I must have something wrong hidden in there that didn't crash the previous version.
[2:31 AM] thebracket: Got it. It crashes when I add a tangent buffer to a non-indexed mesh.
[2:32 AM] thebracket: https://gist.github.com/thebracket/4d5507a7fb3380a911b8912f219c1a67
[2:32 AM] François 🥷🏻: ha! then you would probably need bevyengine/bevy#3120 which allows you to use the attributes you want in the order you want instead of exactly what Bevy shader expect
[2:36 AM] thebracket: That looks like a great PR in general, custom buffer entries are pretty painful.
[2:39 AM] thebracket: Adding an index buffer is interesting. It doesn't crash. Without tangents, you get the expected output:
[2:40 AM] thebracket: With tangents, it doesn't crash - but the data is all over the place.
[2:40 AM] thebracket: (Same index buffer for both)
[2:41 AM] François 🥷🏻: yep, that's the issue, it's using the wrong attribute value as it's not in the order expected
[2:44 AM] thebracket: Yikes, ok. I guess I'll chug along without tangents (and presumably no per-pixel shading, since you typically need tangents for normal map calculation in a pbr pipeline). Thanks!
[3:17 AM] thebracket: With tangents disabled, Pyrite Box works with 0.6.
[3:20 AM] François 🥷🏻: nice!

@Toqozz Toqozz closed this as completed May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants