summaryrefslogtreecommitdiff
path: root/src/platform/platform.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/platform.cc')
-rw-r--r--src/platform/platform.cc21
1 files changed, 3 insertions, 18 deletions
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) {