SDL3 Event Handling: Renamed Enumerations Break Existing Switch Logic
0 reputation · 24 Nov 2022, 15:39 UTC
0 reputation · 24 Nov 2022, 15:39 UTC
We need to validate that our event‑handling code continues to work after migrating from SDL2 to SDL3. The primary concern is the set of event type constants and struct layouts that have been reorganized in the SDL3 API, which can silently break switch statements that rely on SDL2 enumerations.
SDL3 introduces new event type names and removes several legacy constants. The sdl2‑compat layer claims to map most SDL2 events to SDL3, but the mapping is not guaranteed to be exhaustive. Additionally, the event struct layout has changed, so code that accesses fields directly may read incorrect data. We must decide whether to rely on sdl2‑compat for CI testing or to update the code to use the native SDL3 event types.
SDL3 renames most SDL2 event type constants to the SDL_EVENT_* prefix, removes the aggregate SDL_WINDOWEVENT constant, and splits window events into distinct types. The sdl2-compat layer provides macro mappings for many of the renamed constants, but it does not forward SDL3‑only events and does not map the removed SDL_WINDOWEVENT aggregate.
SDL_EVENT_QUITSDL_EVENT_KEY_DOWNSDL_EVENT_KEY_UPSDL_EVENT_MOUSE_MOTIONSDL_EVENT_MOUSE_BUTTON_DOWNSDL_EVENT_MOUSE_BUTTON_UPSDL_EVENT_WINDOW_SHOWNSDL_EVENT_WINDOW_HIDDENSDL_EVENT_WINDOW_EXPOSEDSDL_EVENT_WINDOW_MOVEDSDL_EVENT_WINDOW_RESIZEDSDL_EVENT_WINDOW_SIZE_CHANGEDSDL_EVENT_WINDOW_MINIMIZEDSDL_EVENT_WINDOW_MAXIMIZEDSDL_EVENT_WINDOW_RESTOREDSDL_EVENT_WINDOW_ENTERSDL_EVENT_WINDOW_LEAVESDL_EVENT_WINDOW_FOCUS_GAINEDSDL_EVENT_WINDOW_FOCUS_LOSTSDL_EVENT_WINDOW_CLOSE_REQUESTEDsdl2-compat header defines macros such as #define SDL_QUIT SDL_EVENT_QUIT for the renamed constants that have a direct counterpart.The compatibility layer maps many SDL2 names to SDL3 equivalents, but it cannot map SDL3‑only events (e.g., SDL_EVENT_DISPLAY_ORIENTATION) and it does not provide a macro for the removed SDL_WINDOWEVENT aggregate. Consequently, a switch statement compiled against SDL3 headers with sdl2-compat will:
default case for any SDL3‑only event or for a window event that relied on the subcode field, causing silent drops or incorrect handling.SDL_Event.window fields assuming the SDL2 layout.sdl2-compat) and log event.type for each generated event to verify the actual constant values.default case to your event switch that logs unknown event.type values; run the application under both builds to detect unmapped events.sdl2-compat compatibility headers to confirm which SDL2 constants are mapped and which SDL3 events lack a macro.SDL_WINDOWEVENT cases with explicit handling of the discrete SDL_EVENT_WINDOW_* events, using the appropriate union member (event.window) as defined in SDL3.SDL_EVENT_* constants directly (or retain the sdl2-compat macros if you wish to keep SDL2 source compatibility).To determine whether the current sdl2-compat mapping is sufficient for your codebase, please provide the list of SDL2 event types your code currently handles (e.g., from your existing switch statement). This will let us confirm if any of those are unmapped or if SDL3‑only events need to be added.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.