From 044774dcee440f080e3837a8165a1a17f4c90caf Mon Sep 17 00:00:00 2001 From: Sebastian Emanuel Dawid Date: Mon, 29 Sep 2025 14:40:31 +0200 Subject: [PATCH] Provide weak default implementation for `wgpuInstanceCreateSurface` --- examples/triangle-webgpu.c | 10 +++++++++- src/internal.h | 4 +++- src/webgpu.c | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/triangle-webgpu.c b/examples/triangle-webgpu.c index c31131221..960515095 100644 --- a/examples/triangle-webgpu.c +++ b/examples/triangle-webgpu.c @@ -73,8 +73,16 @@ int main(void) exit(EXIT_FAILURE); } - WGPUAdapter adapter; WGPUSurface surface = glfwCreateWindowWGPUSurface(instance, window); + if (!surface) + { + fprintf(stderr, "Error: Failed to create WebGPU surface.\n"); + wgpuInstanceRelease(instance); + glfwDestroyWindow(window); + glfwTerminate(); + exit(EXIT_FAILURE); + } + WGPUAdapter adapter; WGPUDevice device; WGPUQueue queue; bool success = false; diff --git a/src/internal.h b/src/internal.h index 8037f1d31..eaedb1c68 100644 --- a/src/internal.h +++ b/src/internal.h @@ -367,7 +367,9 @@ typedef struct WGPUSurfaceDescriptor WGPUStringView label; } WGPUSurfaceDescriptor; -extern WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor* descriptor) __attribute((weak)); +#if !defined(_MSC_VER) +WGPUSurface __attribute__((weak)) wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor* descriptor); +#endif #include "platform.h" diff --git a/src/webgpu.c b/src/webgpu.c index 09bbe375f..5af24b411 100644 --- a/src/webgpu.c +++ b/src/webgpu.c @@ -29,6 +29,13 @@ #include #include +#if !defined(_MSC_VER) +WGPUSurface __attribute__((weak)) wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor* descriptor) +{ + return NULL; +} +#endif + GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* handle) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL)