From 2d7b82c2f4622807c249c0f8aac07a4a32c9f0cf Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 16 Jun 2021 00:24:47 -0400 Subject: [PATCH] Do some checks to make sure WGPU_TRACE_DIR is useable if set and exit early if it isn't to avoid the user not being aware that they are failing to collect a trace --- voxygen/src/render/renderer.rs | 57 ++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 8f2c3e8b94..06cf8b6386 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -207,22 +207,47 @@ impl Renderer { ..Default::default() }; - let (device, queue) = futures_executor::block_on( - adapter.request_device( - &wgpu::DeviceDescriptor { - // TODO - label: None, - features: wgpu::Features::DEPTH_CLAMPING - | wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER - | wgpu::Features::PUSH_CONSTANTS - | (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES), - limits, - }, - std::env::var_os("WGPU_TRACE_DIR") - .as_ref() - .map(|v| std::path::Path::new(v)), - ), - )?; + let (device, queue) = futures_executor::block_on(adapter.request_device( + &wgpu::DeviceDescriptor { + // TODO + label: None, + features: wgpu::Features::DEPTH_CLAMPING + | wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER + | wgpu::Features::PUSH_CONSTANTS + | (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES), + limits, + }, + std::env::var_os("WGPU_TRACE_DIR").as_ref().map(|v| { + let path = std::path::Path::new(v); + // We don't want to continue if we can't actually collect the api trace + if !path.exists() { + panic!( + "WGPU_TRACE_DIR is set to the path \"{}\" which doesn't exist", + path.display() + ); + } + if !path.is_dir() { + panic!( + "WGPU_TRACE_DIR is set to the path \"{}\" which is not a directory", + path.display() + ); + } + if path + .read_dir() + .expect("Could not read the directory that is specified by WGPU_TRACE_DIR") + .next() + .is_some() + { + panic!( + "WGPU_TRACE_DIR is set to the path \"{}\" which already contains other \ + files", + path.display() + ); + } + + path + }), + ))?; // Set error handler for wgpu errors // This is better for use than their default because it includes the error in