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/post_process_helper.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/gpu/post_process_helper.cc') diff --git a/src/gpu/post_process_helper.cc b/src/gpu/post_process_helper.cc index 5f2ff56..6026f6e 100644 --- a/src/gpu/post_process_helper.cc +++ b/src/gpu/post_process_helper.cc @@ -14,6 +14,11 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, WGPUTextureFormat format, const char* shader_code) { + // Headless mode: skip pipeline creation + if (device == nullptr) { + return nullptr; + } + WGPUBindGroupLayout bgl = BindGroupLayoutBuilder() .sampler(PP_BINDING_SAMPLER, WGPUShaderStage_Fragment) @@ -40,6 +45,11 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, WGPURenderPipeline create_post_process_pipeline_simple(WGPUDevice device, WGPUTextureFormat format, const char* shader_code) { + // Headless mode: skip pipeline creation + if (device == nullptr) { + return nullptr; + } + WGPUBindGroupLayout bgl = BindGroupLayoutBuilder() .sampler(PP_BINDING_SAMPLER, WGPUShaderStage_Fragment) @@ -67,6 +77,11 @@ static GpuBuffer g_dummy_buffer = {nullptr, 0}; void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, WGPUBindGroup* bind_group, WGPUTextureView input_view, GpuBuffer uniforms, GpuBuffer effect_params) { + // Headless mode: skip bind group creation + if (device == nullptr || pipeline == nullptr) { + return; + } + if (!g_dummy_buffer.buffer) { g_dummy_buffer = gpu_create_buffer(device, 32, WGPUBufferUsage_Uniform); } -- cgit v1.2.3