Events, keyboard & mouseSDL 3.2
SDL_PushEvent
Adds an event to the queue yourself. Safe from any thread: the way a worker thread talks to the main loop.
Signature
bool SDL_PushEvent(SDL_Event *event);
How it works
Most SDL functions must run on the main thread. A loading thread that finished a level cannot touch the renderer, but it can push an event; the main loop then picks it up with SDL_PollEvent and does the main-thread work.
For your own event types, reserve numbers with SDL_RegisterEvents and put your data in event.user (code, data1, data2). SDL copies the event, so a local variable is fine.
Parameters
eventSDL_Event *
The event to add (copied).
Return value
true if queued; false if it was filtered out or the queue is full.
Example
example.cpp
1// worker thread
2SDL_Event ev{};
3ev.type = assetLoadedEvent; // from SDL_RegisterEvents(1)
4ev.user.data1 = loadedMesh;
5SDL_PushEvent(&ev);