From f7a34b7401695a4a9137889eb4eb322694f8c5c9 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 26 Mar 2026 07:34:54 +0100 Subject: fix(src/platform): code review cleanup - platform.h: deduplicate str_view/label_view/platform_wgpu_wait_any (were identical in WIN32 and default branches); remove dead platform_wgpu_set_error_callback and its never-used callback typedefs - platform.cc: remove glfwSetWindowUserPointer(nullptr) + stale comment block; drop if-guard on user pointer fixup in platform_poll; remove redundant aspect_ratio recompute (framebuffer_size_callback owns it) - headless_platform.cc: write g_virtual_time back to state->time in platform_poll; remove never-set g_should_close variable - stub_types.h: remove dead platform_wgpu_set_error_callback and callback typedefs; add comment on non-empty WGPURenderPassColorAttachment handoff(Gemini): platform layer cleaned up, no behaviour change --- src/platform/platform.cc | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'src/platform/platform.cc') diff --git a/src/platform/platform.cc b/src/platform/platform.cc index 29b3af3..ce9ec41 100644 --- a/src/platform/platform.cc +++ b/src/platform/platform.cc @@ -52,16 +52,8 @@ PlatformState platform_init(bool fullscreen, int width, int height) { state.aspect_ratio = (float)state.width / (float)state.height; } - // Store our state in a static pointer or use the window pointer? - // We'll use a pointer to a persistent state. - // For this demo, we can assume the PlatformState persists in main(). - // But we return by value. This is a bit tricky with callbacks. - // We'll fix the callbacks in platform_poll if needed, or just let main pass - // the pointer back. - - glfwSetWindowUserPointer(state.window, - nullptr); // Will be set in main's state - + // User pointer is set on first platform_poll() when the caller's + // PlatformState address is stable. glfwSetKeyCallback(state.window, glfw_key_callback); glfwSetFramebufferSizeCallback(state.window, framebuffer_size_callback); @@ -88,16 +80,9 @@ void platform_shutdown(PlatformState* state) { } void platform_poll(PlatformState* state) { - // Ensure the window has the current state pointer for callbacks - if (glfwGetWindowUserPointer(state->window) != state) { - glfwSetWindowUserPointer(state->window, state); - } - + glfwSetWindowUserPointer(state->window, state); glfwPollEvents(); state->time = glfwGetTime(); - if (state->height > 0) { - state->aspect_ratio = (float)state->width / (float)state->height; - } } bool platform_should_close(PlatformState* state) { -- cgit v1.2.3