Skip to content

Randomly sprite does not render and systems do not function #16120

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

Closed
Frost2779 opened this issue Oct 27, 2024 · 10 comments
Closed

Randomly sprite does not render and systems do not function #16120

Frost2779 opened this issue Oct 27, 2024 · 10 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Machine-Specific This bug is isolated to specific hardware or driver configurations O-Linux Specific to the Linux desktop operating system S-Blocked This cannot move forward until something else changes

Comments

@Frost2779
Copy link

Frost2779 commented Oct 27, 2024

Bevy version

Reproducible on 0.14.2, 0.15.0-rc1, and main.

[Optional] Relevant system information

Rust: 1.82.0
OS: Nobara Linux 40

`AdapterInfo { name: "NVIDIA GeForce RTX 2070 SUPER", vendor: 4318, device: 7812, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "560.35.03", backend: Vulkan }`

I have tested on upstream wgpu and experiences no rendering issues.

What you did

I created a simple project with only the most recent release of bevy as the dependency. I setup the project as needed for what I am trying to accomplish. That being getting a sprite to render to the screen, be able to move around the screen using the middle mouse button, and then use the scroll wheel to be able to zoom in/out.

Upon running the project, I received the following output:

Image

What went wrong

Sometimes, it seems like the sprite doesn't render, and other times, the sprite renders, but the systems seem not to function as expected, seeming to do nothing. Various println have confirmed that the systems are in fact running, and handle proper mouse input, but seem to have no effect. This usually required me to run the app a few times before both the sprite renders and the systems function. Furthermore, even if the mouse systems section is removed, the issue with the sprite randomly not rendering still persists.

  • what were you expecting?
    The sprite would render and the systems would function consistently.

MRE of the project code:

use bevy::{input::{common_conditions::input_pressed, mouse::{MouseMotion, MouseWheel}}, prelude::*};

#[derive(Component)]
struct MainCamera;

fn main() {
    App::new()
        .add_plugins(
            DefaultPlugins
                .set(ImagePlugin::default_nearest())
        )
        .add_systems(Startup, setup)
        .add_systems(Update, (
            mouse_zoom, 
            mouse_pan.run_if(input_pressed(MouseButton::Middle))
        ))
        .run();
}

fn setup(mut commands: Commands, server: Res<AssetServer>) {
    commands.spawn((Camera2d::default(), MainCamera));
    commands.spawn(Sprite{
        image: server.load("placeholder.png"),
        ..default()
    });
}

fn mouse_zoom(
    mut scroll_events: EventReader<MouseWheel>,
    mut query_camera: Query<&mut OrthographicProjection>
) {
    let mut projection = query_camera.single_mut();
    for ev in scroll_events.read() {
        if ev.y > 0. {
            projection.scale /= 1.25;
        } else if ev.y < 0. {
            projection.scale *= 1.25;
        }
    }
}

fn mouse_pan(
    mut evr_motion: EventReader<MouseMotion>,
    mut q_transform: Query<&mut Transform, With<MainCamera>>
) {
    let mut transform = q_transform.single_mut();
    for ev in evr_motion.read() {
        transform.translation.x += ev.delta.x * -1.;
        transform.translation.y += ev.delta.y;
    }
}

Additional information

I believe that the error that I am seeing related to EGL 'eglCreateSyncKHR' can likely be ignored as I see the same error as part of testing wgpu and didn't not experience any rendering difficulties there across multiple examples runs.

@Frost2779 Frost2779 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 27, 2024
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Oct 27, 2024
@alice-i-cecile
Copy link
Member

The specific pattern of behavior (differing behavior across different runs) makes me suspect that this is due to a rendering-related system order ambiguity. The broad category is tracked in #7386.

@Frost2779
Copy link
Author

Is there any kind of override I could provide on my end in the meantime to force a more specific order to combat this problem, or will it need to be fixed upsteam?

@alice-i-cecile
Copy link
Member

If you can figure out what the problem is, you should be able to patch it in your project by adding a dependency between the offending system sets. That's more a backporting strategy than a proper workaround though, and if you do end up figuring out what pair is causing this problem, please do let us know and/or submit a patch.

@Frost2779
Copy link
Author

However, would this rendering ambiguity also be responsible for the systems seeming not to function since they were related to transforming what was rendered?

@alice-i-cecile
Copy link
Member

Probably not; I'm really not sure what's going on there.

@bas-ie
Copy link
Contributor

bas-ie commented Oct 27, 2024

Just to add a data point: can't reproduce on Wayland/AMD card. I'm always suspicious of NVIDIA linux drivers, but you'd think a GeForce RTX 2070 SUPER would be pretty well-supported by now! @Frost2779, if you were interested in a little experimentation, you could try swapping from the proprietary NVIDIA driver to nouveau to see if the problem goes away. Might add a little information to the issue 🤔

@alice-i-cecile alice-i-cecile added O-Linux Specific to the Linux desktop operating system C-Machine-Specific This bug is isolated to specific hardware or driver configurations labels Oct 27, 2024
@eero-lehtinen
Copy link
Contributor

eero-lehtinen commented Oct 27, 2024

I'm pretty sure this is a xwayland + nvidia issue. Basically the window is frozen and the game is otherwise running just fine. It happens to me too and can be fixed by resizing the window after startup or enabling the wayland feature.

Maybe we could rethink the Couldn't get swap chain texture. This often happens with the NVIDIA drivers on Linux. It can be safely ignored. error to somehow force update the window on startup. It seems that it infact can't be safely ignored.

@Frost2779
Copy link
Author

Yea I can confirm that @eero-lehtinen's workaround of enabling the wayland feature solved this for me. I can't recreate the original issue after enabling.

@alice-i-cecile alice-i-cecile added S-Blocked This cannot move forward until something else changes and removed S-Needs-Investigation This issue requires detective work to figure out what's going wrong labels Oct 27, 2024
@alice-i-cecile
Copy link
Member

I'm going to call this "upstream's bug" and close it out :(

@eero-lehtinen
Copy link
Contributor

There might be something we can do. I experimented with some changes and I was able to kind of fix this. I just didn't realise this was still an issue because I always have wayland enabled.

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 C-Machine-Specific This bug is isolated to specific hardware or driver configurations O-Linux Specific to the Linux desktop operating system S-Blocked This cannot move forward until something else changes
Projects
None yet
Development

No branches or pull requests

4 participants