From 42de5c4e5aeb486b4afb5b73bcb6a9d5ba567cbd Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 16 Feb 2026 15:15:40 +0100 Subject: fix(headless): add nullptr checks for GPU resource creation - NodeRegistry::create_texture: skip texture creation when device is nullptr - Post-process helpers: skip pipeline/bind group creation in headless mode - SamplerCache: return nullptr for headless mode - BindGroupLayoutBuilder/BindGroupBuilder: skip creation with null device - RenderPipelineBuilder: skip shader module and pipeline creation in headless - PlaceholderEffect: skip sampler creation in headless mode - RotatingCubeEffect: early return in constructor for headless mode WIP: Some effects (GaussianBlur, etc.) still need headless checks Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/pipeline_builder.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/gpu/pipeline_builder.h') diff --git a/src/gpu/pipeline_builder.h b/src/gpu/pipeline_builder.h index 87b9190..a258b49 100644 --- a/src/gpu/pipeline_builder.h +++ b/src/gpu/pipeline_builder.h @@ -38,14 +38,17 @@ class RenderPipelineBuilder { RenderPipelineBuilder& shader(const char* wgsl, bool compose = true) { shader_text_ = compose ? ShaderComposer::Get().Compose({}, wgsl) : wgsl; - WGPUShaderSourceWGSL wgsl_src{}; - wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL; - wgsl_src.code = str_view(shader_text_.c_str()); - WGPUShaderModuleDescriptor shader_desc{}; - shader_desc.nextInChain = &wgsl_src.chain; - shader_module_ = wgpuDeviceCreateShaderModule(device_, &shader_desc); - desc_.vertex.module = shader_module_; - desc_.vertex.entryPoint = str_view("vs_main"); + // Headless mode: skip shader module creation + if (device_ != nullptr) { + WGPUShaderSourceWGSL wgsl_src{}; + wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL; + wgsl_src.code = str_view(shader_text_.c_str()); + WGPUShaderModuleDescriptor shader_desc{}; + shader_desc.nextInChain = &wgsl_src.chain; + shader_module_ = wgpuDeviceCreateShaderModule(device_, &shader_desc); + desc_.vertex.module = shader_module_; + desc_.vertex.entryPoint = str_view("vs_main"); + } return *this; } @@ -85,6 +88,11 @@ class RenderPipelineBuilder { } WGPURenderPipeline build() { + // Headless mode: skip pipeline creation + if (device_ == nullptr) { + return nullptr; + } + color_.writeMask = WGPUColorWriteMask_All; if (has_blend_) color_.blend = &blend_; -- cgit v1.2.3