From b36002dd5097747918094e4d7cdcce5cb2f2b1d7 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Wed, 10 Sep 2025 16:07:12 +0200 Subject: [PATCH] Handle shader compilation error --- base/sources/backends/metal_gpu.m | 12 +++++------- base/sources/iron.h | 4 ++++ base/sources/iron_gpu.c | 5 ++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index 07249317..6a6b6f36 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -321,13 +321,6 @@ void gpu_disable_scissor() { } void gpu_set_pipeline_internal(gpu_pipeline_t *pipeline) { - for (int i = 0; i < GPU_MAX_TEXTURES; ++i) { - current_textures[i] = NULL; - } - if (pipeline->impl.pipeline == NULL) { - return; - } - current_pipeline = pipeline; id pipe = (__bridge id)pipeline->impl.pipeline; [command_encoder setRenderPipelineState:pipe]; id depth_state = (__bridge id)pipeline->impl.depth; @@ -423,6 +416,11 @@ void gpu_pipeline_destroy_internal(gpu_pipeline_t *pipeline) { } void gpu_pipeline_compile(gpu_pipeline_t *pipeline) { + if (pipeline->vertex_shader->impl.length == 0 || pipeline->fragment_shader->impl.length == 0) { + // Shader compilation error + return; + } + id device = get_metal_device(); NSError *error = nil; id library = [device newLibraryWithSource:[[NSString alloc] initWithBytes:pipeline->vertex_shader->impl.source length:pipeline->vertex_shader->impl.length encoding:NSUTF8StringEncoding] options:nil error:&error]; diff --git a/base/sources/iron.h b/base/sources/iron.h index f3431498..a1e3fc8f 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -1018,6 +1018,10 @@ void gpu_create_shaders_from_kong(char *kong, char **vs, char **fs, int *vs_size if (kong_error) { console_info("Warning: Shader compilation failed"); free(tokens.t); + #if defined(__APPLE__) + *vs = ""; + *fs = ""; + #endif return; } allocate_globals(); diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index a9914223..6ddcab1d 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -73,6 +73,9 @@ void gpu_begin(gpu_texture_t **targets, int count, gpu_texture_t *depth_buffer, } void gpu_draw() { + if (current_pipeline == NULL || current_pipeline->impl.pipeline == NULL) { + return; + } gpu_constant_buffer_unlock(&constant_buffer); gpu_set_constant_buffer(&constant_buffer, constant_buffer_index * GPU_CONSTANT_BUFFER_SIZE, GPU_CONSTANT_BUFFER_SIZE); gpu_draw_internal(); @@ -294,13 +297,13 @@ void gpu_texture_destroy(gpu_texture_t *texture) { } void gpu_set_pipeline(gpu_pipeline_t *pipeline) { + current_pipeline = pipeline; for (int i = 0; i < GPU_MAX_TEXTURES; ++i) { current_textures[i] = NULL; } if (pipeline->impl.pipeline == NULL) { return; } - current_pipeline = pipeline; gpu_set_pipeline_internal(pipeline); }