Skip to content

Commit 29bd10c

Browse files
authored
Merge pull request #115 from cschreib/sdl_sigint
Fix SDL preventing Ctrl+C
2 parents bbb8132 + 2373dba commit 29bd10c

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

examples/opengl-sdl-emscripten/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ int main(int argc, char* argv[]) {
114114
const std::size_t window_width = 800u;
115115
const std::size_t window_height = 600u;
116116

117-
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
117+
// Prevent SDL from capturing Ctrl+C SIGINT
118+
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
119+
120+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0) {
118121
throw gui::exception(
119122
"SDL_Init", "Could not initialise SDL: " + std::string(SDL_GetError()) + ".");
120123
}

examples/opengl-sdl/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ int main(int argc, char* argv[]) {
5454
const std::size_t window_width = 800u;
5555
const std::size_t window_height = 600u;
5656

57-
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
57+
// Prevent SDL from capturing Ctrl+C SIGINT
58+
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
59+
60+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0) {
5861
throw gui::exception(
5962
"SDL_Init", "Could not initialise SDL: " + std::string(SDL_GetError()) + ".");
6063
}

examples/sdl-emscripten/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ int main(int argc, char* argv[]) {
9797
const std::size_t window_width = 800u;
9898
const std::size_t window_height = 600u;
9999

100-
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
100+
// Prevent SDL from capturing Ctrl+C SIGINT
101+
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
102+
103+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0) {
101104
throw gui::exception(
102105
"SDL_Init", "Could not initialise SDL: " + std::string(SDL_GetError()) + ".");
103106
}

examples/sdl/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ int main(int argc, char* argv[]) {
3535
const std::size_t window_width = 800u;
3636
const std::size_t window_height = 600u;
3737

38-
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
38+
// Prevent SDL from capturing Ctrl+C SIGINT
39+
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
40+
41+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0) {
3942
throw gui::exception(
4043
"SDL_Init", "Could not initialise SDL: " + std::string(SDL_GetError()) + ".");
4144
}

test/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ int main(int /*argc*/, char* /*argv*/[]) {
276276
#if defined(GLSFML_GUI)
277277
sf::Window window;
278278
#elif defined(SDL_GUI) || defined(GLSDL_GUI)
279-
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
279+
// Prevent SDL from capturing Ctrl+C SIGINT
280+
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
281+
282+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0) {
280283
throw gui::exception(
281284
"SDL_Init", "Could not initialise SDL: " + std::string(SDL_GetError()) + ".");
282285
}

0 commit comments

Comments
 (0)