SDL: The parameter to SDL_AppEvent() should be non-const

From 575d9cda6f169b06e8f500acb8d3534408216185 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 3 Sep 2024 07:45:30 -0700
Subject: [PATCH] The parameter to SDL_AppEvent() should be non-const

This allows functions like SDL_ConvertEventToRenderCoordinates() to work without having to copy the event.

Fixes https://github.com/libsdl-org/SDL/issues/10691
---
 docs/README-main-functions.md                                   | 2 +-
 examples/audio/01-simple-playback/simple-playback.c             | 2 +-
 .../02-simple-playback-callback/simple-playback-callback.c      | 2 +-
 examples/audio/03-load-wav/load-wav.c                           | 2 +-
 examples/camera/01-read-and-draw/read-and-draw.c                | 2 +-
 examples/game/01-snake/snake.c                                  | 2 +-
 examples/pen/01-drawing-lines/drawing-lines.c                   | 2 +-
 examples/renderer/01-clear/renderer-clear.c                     | 2 +-
 examples/renderer/02-primitives/renderer-primitives.c           | 2 +-
 examples/template.c                                             | 2 +-
 include/SDL3/SDL_init.h                                         | 2 +-
 include/SDL3/SDL_main.h                                         | 2 +-
 test/loopwave.c                                                 | 2 +-
 test/testaudio.c                                                | 2 +-
 test/testaudiorecording.c                                       | 2 +-
 test/testcamera.c                                               | 2 +-
 test/testdropfile.c                                             | 2 +-
 test/testgpu_simple_clear.c                                     | 2 +-
 test/testpen.c                                                  | 2 +-
 test/testsprite.c                                               | 2 +-
 20 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/docs/README-main-functions.md b/docs/README-main-functions.md
index 98bf888a3ad3f..f7e797ac4d88f 100644
--- a/docs/README-main-functions.md
+++ b/docs/README-main-functions.md
@@ -178,7 +178,7 @@ not check the  event queue in this function (SDL_AppEvent exists for that).
 Next:
 
 ```c
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event);
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event);

This will be called whenever an SDL event arrives. Your app should not call
diff --git a/examples/audio/01-simple-playback/simple-playback.c b/examples/audio/01-simple-playback/simple-playback.c
index ca4fc8c49fd02…7c19e9e2821a1 100644
— a/examples/audio/01-simple-playback/simple-playback.c
+++ b/examples/audio/01-simple-playback/simple-playback.c
@@ -51,7 +51,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/examples/audio/02-simple-playback-callback/simple-playback-callback.c b/examples/audio/02-simple-playback-callback/simple-playback-callback.c
index a612c45b40537…2e6078435a960 100644
— a/examples/audio/02-simple-playback-callback/simple-playback-callback.c
+++ b/examples/audio/02-simple-playback-callback/simple-playback-callback.c
@@ -83,7 +83,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/examples/audio/03-load-wav/load-wav.c b/examples/audio/03-load-wav/load-wav.c
index 7f5d45845066e…512dff7bd2c7c 100644
— a/examples/audio/03-load-wav/load-wav.c
+++ b/examples/audio/03-load-wav/load-wav.c
@@ -65,7 +65,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/examples/camera/01-read-and-draw/read-and-draw.c b/examples/camera/01-read-and-draw/read-and-draw.c
index 1a0363d816da6…6b33443c313bf 100644
— a/examples/camera/01-read-and-draw/read-and-draw.c
+++ b/examples/camera/01-read-and-draw/read-and-draw.c
@@ -56,7 +56,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/examples/game/01-snake/snake.c b/examples/game/01-snake/snake.c
index ac4b22357835d…65ef58c6de232 100644
— a/examples/game/01-snake/snake.c
+++ b/examples/game/01-snake/snake.c
@@ -305,7 +305,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
return SDL_APP_CONTINUE;
}

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
SnakeContext *ctx = &((AppState *)appstate)->snake_ctx;
switch (event->type) {
diff --git a/examples/pen/01-drawing-lines/drawing-lines.c b/examples/pen/01-drawing-lines/drawing-lines.c
index 47c8d8686c375…c772e9a26b632 100644
— a/examples/pen/01-drawing-lines/drawing-lines.c
+++ b/examples/pen/01-drawing-lines/drawing-lines.c
@@ -52,7 +52,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/examples/renderer/01-clear/renderer-clear.c b/examples/renderer/01-clear/renderer-clear.c
index 7c7d6b6b3d055…e678f1ccb4321 100644
— a/examples/renderer/01-clear/renderer-clear.c
+++ b/examples/renderer/01-clear/renderer-clear.c
@@ -39,7 +39,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/examples/renderer/02-primitives/renderer-primitives.c b/examples/renderer/02-primitives/renderer-primitives.c
index 34a6e939013ec…cb5f57c148247 100644
— a/examples/renderer/02-primitives/renderer-primitives.c
+++ b/examples/renderer/02-primitives/renderer-primitives.c
@@ -39,7 +39,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/examples/template.c b/examples/template.c
index 0404b5b119698…a5cc995688bb0 100644
— a/examples/template.c
+++ b/examples/template.c
@@ -29,7 +29,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS; /
end the program, reporting success to the OS. */
diff --git a/include/SDL3/SDL_init.h b/include/SDL3/SDL_init.h
index 5a13947751a33…d4d4c2a4bec3e 100644
— a/include/SDL3/SDL_init.h
+++ b/include/SDL3/SDL_init.h
@@ -96,7 +96,7 @@ typedef enum SDL_AppResult

typedef SDL_AppResult (SDLCALL *SDL_AppInit_func)(void **appstate, int argc, char *argv);
typedef SDL_AppResult (SDLCALL *SDL_AppIterate_func)(void *appstate);
-typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, const SDL_Event *event);
+typedef SDL_AppResult (SDLCALL *SDL_AppEvent_func)(void *appstate, SDL_Event *event);
typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate);

/**
diff --git a/include/SDL3/SDL_main.h b/include/SDL3/SDL_main.h
index de3c18771dabd…12e8ffdca2112 100644
— a/include/SDL3/SDL_main.h
+++ b/include/SDL3/SDL_main.h
@@ -359,7 +359,7 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppIterate(void *appstate);

  • \sa SDL_AppInit
  • \sa SDL_AppIterate
    */
    -extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, const SDL_Event *event);
    +extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, SDL_Event *event);

/**

  • App-implemented deinit entry point for SDL_MAIN_USE_CALLBACKS apps.
    diff --git a/test/loopwave.c b/test/loopwave.c
    index 0379b6847c10a…c8d67fc6024df 100644
    — a/test/loopwave.c
    +++ b/test/loopwave.c
    @@ -120,7 +120,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
    return SDL_APP_CONTINUE;
    }

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
return (event->type == SDL_EVENT_QUIT) ? SDL_APP_SUCCESS : SDL_APP_CONTINUE;
}
diff --git a/test/testaudio.c b/test/testaudio.c
index 2437b9a0c9926…8ffd0a3c4251f 100644
— a/test/testaudio.c
+++ b/test/testaudio.c
@@ -1114,7 +1114,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)

static SDL_bool saw_event = SDL_FALSE;

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
Thing *thing = NULL;

diff --git a/test/testaudiorecording.c b/test/testaudiorecording.c
index 302f3fdfa76ac…c83c9bc4e0e5d 100644
— a/test/testaudiorecording.c
+++ b/test/testaudiorecording.c
@@ -149,7 +149,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv)
return SDL_APP_CONTINUE;
}

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
diff --git a/test/testcamera.c b/test/testcamera.c
index 01107049e0df0…0ebdaa9c8eeec 100644
— a/test/testcamera.c
+++ b/test/testcamera.c
@@ -216,7 +216,7 @@ static int FlipCamera(void)
return SDL_APP_CONTINUE;
}

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
switch (event->type) {
case SDL_EVENT_KEY_DOWN: {
diff --git a/test/testdropfile.c b/test/testdropfile.c
index 2f71baa00f95d…78f69498d3c93 100644
— a/test/testdropfile.c
+++ b/test/testdropfile.c
@@ -70,7 +70,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
return SDL_APP_FAILURE;
}

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
dropfile_dialog *dialog = appstate;
if (event->type == SDL_EVENT_DROP_BEGIN) {
diff --git a/test/testgpu_simple_clear.c b/test/testgpu_simple_clear.c
index f2aac760622cb…904526d5de055 100644
— a/test/testgpu_simple_clear.c
+++ b/test/testgpu_simple_clear.c
@@ -70,7 +70,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
return SDL_APP_CONTINUE;
}

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
return SDLTest_CommonEventMainCallbacks(state, event);
}
diff --git a/test/testpen.c b/test/testpen.c
index f1e7544fca429…7cdb228ce2d11 100644
— a/test/testpen.c
+++ b/test/testpen.c
@@ -107,7 +107,7 @@ static Pen *FindPen(SDL_PenID which)
return NULL;
}

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
Pen *pen = NULL;

diff --git a/test/testsprite.c b/test/testsprite.c
index 1af2dc2e7a11f…15f645a641695 100644
— a/test/testsprite.c
+++ b/test/testsprite.c
@@ -551,7 +551,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv)
}

-SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
+SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
return SDLTest_CommonEventMainCallbacks(state, event);
}