Fix lifetime of cached textures (#4333)

* Fix in-use textures being destroyed

* Remove ImageTexture refs

* Review
This commit is contained in:
Timon
2026-07-14 13:23:31 +02:00
committed by Keavon Chambers
parent ba0a97aefe
commit 7e29fe9a31
18 changed files with 100 additions and 79 deletions

View File

@@ -67,13 +67,11 @@ pub async fn export_document(
std::fs::write(&output_path, svg)?;
log::info!("Exported SVG to: {}", output_path.display());
}
RenderOutputType::Texture(image_texture) => {
RenderOutputType::Texture(texture) => {
// Convert GPU texture to CPU buffer
let gpu_raster = Raster::<GPU>::new_gpu(image_texture.as_ref().clone());
let gpu_raster = Raster::<GPU>::new_gpu(texture);
let cpu_raster: Raster<CPU> = gpu_raster.convert(Footprint::BOUNDLESS, wgpu_executor).await;
let (data, width, height) = cpu_raster.to_flat_u8();
// Explicitly drop texture to make sure it lives long enough
std::mem::drop(image_texture);
// Encode and write raster image
write_raster_image(output_path, file_type, data, width, height, transparent)?;
@@ -202,11 +200,9 @@ pub async fn export_gif(
// Extract RGBA data from result
let (data, img_width, img_height) = match result {
TaggedValue::RenderOutput(output) => match output.data {
RenderOutputType::Texture(image_texture) => {
let gpu_raster = Raster::<GPU>::new_gpu(image_texture.as_ref().clone());
RenderOutputType::Texture(texture) => {
let gpu_raster = Raster::<GPU>::new_gpu(texture);
let cpu_raster: Raster<CPU> = gpu_raster.convert(Footprint::BOUNDLESS, wgpu_executor).await;
// Explicitly drop texture to make sure it lives long enough
std::mem::drop(image_texture);
cpu_raster.to_flat_u8()
}
RenderOutputType::Buffer { data, width, height } => (data, width, height),