-1

我正在从文件中加载纹理作为 aVec<u8>并将该数据转换为纹理,当我将该纹理添加到资产资源以获取 aHandle<Texture>时,它会导致两个错误,第一个来自日志记录系统并说gpu_alloc::block: Memory block wasn't deallocated第二个(我假设是相关的)是thread 'main' panicked at 'range end index 32896 out of range for slice of length 32768'。这一切似乎都源于这个代码块

                 Ok(pak) => {
                    let mut assets : CurrentlyLoadedAssets = CurrentlyLoadedAssets::default();
                    for texture in pak.textures {

                        //Creates texture from data and loads it into the resource for a handle
                        let texture_asset: Texture = Texture::new(Extent3d { width: 32, height: 32, depth: 1 }, TextureDimension::D2, texture.1, Rgba8UnormSrgb);

                        //This is causing problems
                        let texture_handle: Handle<Texture> = textures.add(texture_asset);

                        println!("Loading: {}", &texture.0);
                        assets.textures.insert(texture.0, texture_handle);
                        //Problems end here
                    }
                    println!("Done getting assets");
                    commands.insert_resource(assets);
                }

知道我需要改变什么来解决这个问题吗?

4

1 回答 1

0

我解决了这个问题。

let texture_asset: Texture = Texture::new(Extent3d { width: 32, height: 32, depth: 1 }, TextureDimension::D2, texture.1, Rgba8UnormSrgb);

应该

texture_asset: Texture = Texture::new(Extent3d { width: 256, height: 256, depth: 1 }, TextureDimension::D2, texture.1, Rgba8UnormSrgb);

不同之处在于宽度和高度必须与您尝试加载的图像相同Vec<u8>,我使用的是 256x256 的测试图像,而不是我要使用的 32x32 精灵。

于 2021-06-28T01:26:14.590 回答