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

signal: 11, SIGSEGV: invalid memory reference #81

Open
oli-obk opened this issue Apr 4, 2016 · 4 comments
Open

signal: 11, SIGSEGV: invalid memory reference #81

oli-obk opened this issue Apr 4, 2016 · 4 comments
Labels

Comments

@oli-obk
Copy link

oli-obk commented Apr 4, 2016

So I'm not sure where to post this, and it's hard to reproduce since it's UB.

I added a test to this crate

Cargo.toml changes

[dev-dependencies]
piston_window = "0.40"
rand = "0.3"

tests/smoke.rs

extern crate gfx_texture;
extern crate piston_window;
extern crate rand;
extern crate image as im;

use piston_window::*;

#[test]
fn create() {
    let window: PistonWindow = WindowSettings::new("Hello Piston!", (640, 480))
        .build()
        .expect("Failed to build PistonWindow");

    let mut img = im::ImageBuffer::new(2, 2);
    for x in 0..2 {
        for y in 0..2 {
            img.put_pixel(x, y,
                im::Rgba([rand::random(), rand::random(), rand::random(), 255]));
        }
    }
    let mut factory = window.factory.borrow_mut();
    let factory = &mut *factory;
    Texture::from_image(factory, &img, &TextureSettings::new()).unwrap();
}

#[test]
fn update() {
    let window: PistonWindow = WindowSettings::new("Hello Piston!", (640, 480))
        .build()
        .expect("Failed to build PistonWindow");

    let mut img = im::ImageBuffer::new(2, 2);
    for x in 0..2 {
        for y in 0..2 {
            img.put_pixel(x, y,
                im::Rgba([rand::random(), rand::random(), rand::random(), 255]));
        }
    }
    let mut factory = window.factory.borrow_mut();
    let factory = &mut *factory;
    let mut tex = Texture::from_image(factory, &img, &TextureSettings::new()).unwrap();
    tex.update(&mut *window.encoder.borrow_mut(), &img).unwrap();
}

renaming the update test to segfault prevents the segfault and gives a normal panic. So this might not be reproducable on the target machine.

splitting the window.encoder.borrow_mut() like the factory into multiple bindings will also not segfault on my machine.

I'm using rustc 1.9.0-nightly (30a3849f2 2016-03-30)

@kvark
Copy link
Member

kvark commented Apr 4, 2016

Do you have a call stack?

@bvssvni
Copy link
Member

bvssvni commented Apr 4, 2016

The window might be running out of scope before the texture creation/update.

Try drop(window); at the end.

@kvark
Copy link
Member

kvark commented Apr 4, 2016

@oli-obk is it related to gfx-rs/gfx#928 ?

@oli-obk
Copy link
Author

oli-obk commented Apr 5, 2016

nope, completely unrelated, it was just found while trying to create an MCVE for that.

@bvssvni bvssvni added the bug label Apr 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants