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

Seg Fault When Creating Sprite #2661

Closed
Ktoks opened this issue Aug 15, 2021 · 9 comments
Closed

Seg Fault When Creating Sprite #2661

Ktoks opened this issue Aug 15, 2021 · 9 comments
Labels
A-Audio Sounds playback and modification C-Bug An unexpected or incorrect behavior C-Startup A crash that occurs when first attempting to run a Bevy app O-Linux Specific to the Linux desktop operating system P-Crash A sudden unexpected crash

Comments

@Ktoks
Copy link

Ktoks commented Aug 15, 2021

Bevy version = 0.5

Commit Hash = 9d45353

Operating system & version

Windows 10 build 21390.co_release.210521-1658 , and Ubuntu 20.04 (on WSL2)

What you did

The following code:

use bevy::prelude::*;

const PLAYER_SPRITE: &str = "player_a_01.png";

// entity, component, system, resource

fn main() {
    App::build()
        .insert_resource(ClearColor(Color::rgb(0.04, 0.04, 0.04)))
        .insert_resource(WindowDescriptor {
            title: "Rust Invaders!".to_string(),
            width: 598.0,
            height: 676.0,
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup.system())
        .run();
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut materials: ResMut<Assets<ColorMaterial>>,
    mut windows: ResMut<Windows>,
) {
    // camera
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());

    // position window
    let window = windows.get_primary_mut().unwrap();
    window.set_position(IVec2::new(1920, 1080));

    // spawn sprite
    commands.spawn_bundle(SpriteBundle {
        material: materials.add(asset_server.load(PLAYER_SPRITE).into()),
        ..Default::default()
    });
}

What you expected to happen

Create a sprite- display it on the screen in a window.

What actually happened

Segmentation fault immediately

Additional information

Bevy examples now work on windows Machine.

@Ktoks Ktoks added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 15, 2021
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen P-Crash A sudden unexpected crash and removed S-Needs-Triage This issue needs to be labelled labels Aug 16, 2021
@Ktoks
Copy link
Author

Ktoks commented Aug 16, 2021

If you want to see what I was attempting to build- I was following the tutorial at the following link:

https://youtu.be/Yb3vInxzKGE

@mockersf
Copy link
Member

I don't think anything in that code should segfault... Do you have more details?

Could you retry without the position window block which is the only somewhat unusual code that I see?

    // position window
    let window = windows.get_primary_mut().unwrap();
    window.set_position(IVec2::new(1920, 1080));

@Ktoks
Copy link
Author

Ktoks commented Aug 22, 2021

Sure can, I'll give it a shot. Sorry for the delayed response I've been sick.

@Ktoks
Copy link
Author

Ktoks commented Aug 22, 2021

So after implementing the change you suggested, it works on my windows machine, but still segfaults on WSL Ubuntu. As for 'more details', what else do you need from me?
I'm running this on two installs of rust- one on Windows- which seems to be working as intended now, and one on WSL Ubuntu 20- which is still segmentation faulting.
I am not overly concerned that it doesn't work on WSL for me, it's for those who might have this issue in the future now. I would eventually like to be able to test in both environments though.
New code that works in Windows but segfaults in Linux:

use bevy::prelude::*;
const PLAYER_SPRITE: &str = "player_b_01.png";
// entity, component, system, resource
fn main() {
    App::build()
        .insert_resource(ClearColor(Color::rgb(0.04, 0.04, 0.04)))
        .insert_resource(WindowDescriptor {
            title: "Rust Invaders!".to_string(),
            width: 598.0,
            height: 676.0,
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup.system())
        .run();

}
fn setup(mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
asset_server: Res<AssetServer>,
) {
    // camera
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
    // spawn sprite
    commands.spawn_bundle(SpriteBundle {
        material: materials.add(asset_server.load(PLAYER_SPRITE).into()),
        ..Default::default()
    });
}

@Ktoks
Copy link
Author

Ktoks commented Aug 23, 2021

After further testing- it causes a segfault in the line:

.add_plugins(DefaultPlugins)

@Ktoks
Copy link
Author

Ktoks commented Aug 23, 2021

I don't know if this is a useful error, I commented out the .add_plugins... line from above:
thread 'main' panicked at 'Requested resource does not exist: bevy_asset::asset_server::AssetServer', /home/kacy/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.5.0/src/system/system_param.rs:244:17
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

@shinaka
Copy link

shinaka commented Oct 7, 2021

This is actually because alsa can't find a sound device at the default '0' in WSL2. I'm not entirely sure how to fix this though, as wslg has pulseaudio setup and other apps have no issue playing audio.

@alice-i-cecile alice-i-cecile added A-Audio Sounds playback and modification O-Linux Specific to the Linux desktop operating system C-Startup A crash that occurs when first attempting to run a Bevy app and removed A-Rendering Drawing game state to the screen labels Dec 21, 2021
@AxiomaticSemantics
Copy link
Contributor

AxiomaticSemantics commented Jan 6, 2023

This issue should probably be renamed to: Pulseaudio on WSL2 causes crash on startup due not being able to find audio device

@SolarLiner
Copy link
Contributor

Fixed by #2269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Audio Sounds playback and modification C-Bug An unexpected or incorrect behavior C-Startup A crash that occurs when first attempting to run a Bevy app O-Linux Specific to the Linux desktop operating system P-Crash A sudden unexpected crash
Projects
Status: Done
Development

No branches or pull requests

6 participants