From 4b022e571c522070369bc2b976b5cbfd41e8e89a Mon Sep 17 00:00:00 2001 From: Brayden Lee Date: Tue, 23 Dec 2025 15:08:00 -0500 Subject: [PATCH] Compile-time check for correct padding and alignment in ImVec2 --- imgui.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 2c8fecef6..303923104 100644 --- a/imgui.h +++ b/imgui.h @@ -76,7 +76,7 @@ Index of this file: // Includes #include // FLT_MIN, FLT_MAX #include // va_list, va_start, va_end -#include // ptrdiff_t, NULL +#include // ptrdiff_t, NULL, offsetof #include // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp // Define attributes of all API symbols declarations (e.g. for DLL under Windows) @@ -303,6 +303,8 @@ struct ImVec2 IM_VEC2_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2. #endif }; +static_assert(offsetof(ImVec2, y) - offsetof(ImVec2, x) == sizeof(float), "Cannot compile ImVec2 due to an alignment/padding violation.\ + Please reply to (or start) the issue with your compiler version and flags at https://github.com/ocornut/imgui/issues."); // ImVec4: 4D vector used to store clipping rectangles, colors etc. [Compile-time configurable type] struct ImVec4