直接向 Assets<Texture> 资源添加纹理会导致 gpu_alloc 错误
Directly adding textures to Assets<Texture> resource causes a gpu_alloc error
我正在从文件中加载纹理作为 Vec<u8>
并将该数据转换为纹理,当我将该纹理添加到资产资源以获取 Handle<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);
}
知道我需要更改什么来解决这个问题吗?
我找到问题了
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 精灵我'我要用了。
我正在从文件中加载纹理作为 Vec<u8>
并将该数据转换为纹理,当我将该纹理添加到资产资源以获取 Handle<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);
}
知道我需要更改什么来解决这个问题吗?
我找到问题了
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 精灵我'我要用了。