"Out of Memory" error

#1

Hi,
I am getting an “out of memory” error trying to load a self-generated texture. This is a simplified version of the function I’m using to generate it:

fn gen_texture(
    size_grid: usize,
    texture_res: usize,
) -> TextureData {
    let color: Rgb<encoding::Linear<encoding::Srgb>, f32> = Rgb::new(0.9, 0.0, 0.0);
    let data: Vec<Rgb32Sfloat> = vec![color.into(); size_grid * size_grid * texture_res * texture_res];

    TextureData(
        TextureBuilder::new()
            .with_data_width((size_grid * texture_res) as u32)
            .with_data_height((size_grid * texture_res) as u32)
            .with_data(data),
    )
}

I’m calling it with size_grid=200 and texture_res=2. The resulting vector is 160000 pixels long, which should correspond to ~2.5MB if my calculations are correct. It doesn’t seem to be anywhere close to big.
Can anyone see anything wrong with my code?

#2

I don’t know exactly what’s wrong with your code, but amethyst_ui uses the same API to dynamically generate textures. https://github.com/amethyst/amethyst/blob/master/amethyst_ui/src/glyphs.rs#L626

I see that it uses different (and more) parameters so maybe you could try experimenting with them.

3 Likes
#3

That was it! Adding these two helped:

            .with_kind(Kind::D2((size_grid * texture_res) as u32, (size_grid * texture_res) as u32, 1, 1))
            .with_view_kind(ViewKind::D2)

Apparently, by default the builder is expecting 1-dimensional textures.
Thanks!

2 Likes