Skip to content
Snippets Groups Projects
Commit 03759ccf authored by deuce's avatar deuce
Browse files

Uninitialize SDL video before trying to initialize any other video output.

This fixes the Linux crash on exit in SDL when X11 mode is used (and possible
others).
parent e0599ad5
No related branches found
No related tags found
No related merge requests found
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO) #if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#include "sdl_con.h" #include "sdl_con.h"
#include "sdlfuncs.h"
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#include "win32cio.h" #include "win32cio.h"
...@@ -168,6 +169,11 @@ int try_sdl_init(int mode) ...@@ -168,6 +169,11 @@ int try_sdl_init(int mode)
#ifndef NO_X #ifndef NO_X
int try_x_init(int mode) int try_x_init(int mode)
{ {
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
if (sdl_video_initialized)
sdl.QuitSubSystem(SDL_INIT_VIDEO);
#endif
if(!x_init()) { if(!x_init()) {
cio_api.mode=CIOLIB_MODE_X; cio_api.mode=CIOLIB_MODE_X;
cio_api.mouse=1; cio_api.mouse=1;
...@@ -205,6 +211,11 @@ int try_x_init(int mode) ...@@ -205,6 +211,11 @@ int try_x_init(int mode)
int try_curses_init(int mode) int try_curses_init(int mode)
{ {
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
if (sdl_video_initialized)
sdl.QuitSubSystem(SDL_INIT_VIDEO);
#endif
if(curs_initciolib(mode)) { if(curs_initciolib(mode)) {
if(mode==CIOLIB_MODE_AUTO) if(mode==CIOLIB_MODE_AUTO)
mode=CIOLIB_MODE_CURSES; mode=CIOLIB_MODE_CURSES;
...@@ -233,6 +244,11 @@ int try_curses_init(int mode) ...@@ -233,6 +244,11 @@ int try_curses_init(int mode)
int try_ansi_init(int mode) int try_ansi_init(int mode)
{ {
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
if (sdl_video_initialized)
sdl.QuitSubSystem(SDL_INIT_VIDEO);
#endif
if(ansi_initciolib(mode)) { if(ansi_initciolib(mode)) {
cio_api.mode=CIOLIB_MODE_ANSI; cio_api.mode=CIOLIB_MODE_ANSI;
cio_api.mouse=0; cio_api.mouse=0;
...@@ -257,6 +273,11 @@ int try_ansi_init(int mode) ...@@ -257,6 +273,11 @@ int try_ansi_init(int mode)
#endif #endif
int try_conio_init(int mode) int try_conio_init(int mode)
{ {
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
if (sdl_video_initialized)
sdl.QuitSubSystem(SDL_INIT_VIDEO);
#endif
/* This should test for something or other */ /* This should test for something or other */
if(win32_initciolib(mode)) { if(win32_initciolib(mode)) {
if(mode==CIOLIB_MODE_AUTO) if(mode==CIOLIB_MODE_AUTO)
......
...@@ -25,7 +25,7 @@ struct sdlfuncs sdl; ...@@ -25,7 +25,7 @@ struct sdlfuncs sdl;
static int sdl_funcs_loaded=0; static int sdl_funcs_loaded=0;
static int sdl_initialized=0; static int sdl_initialized=0;
static int sdl_audio_initialized=0; static int sdl_audio_initialized=0;
static int sdl_video_initialized=0; int sdl_video_initialized=0;
static int (*sdl_drawing_thread)(void *data)=NULL; static int (*sdl_drawing_thread)(void *data)=NULL;
static void (*sdl_exit_drawing_thread)(void)=NULL; static void (*sdl_exit_drawing_thread)(void)=NULL;
static int main_returned=0; static int main_returned=0;
......
...@@ -79,6 +79,7 @@ struct sdlfuncs { ...@@ -79,6 +79,7 @@ struct sdlfuncs {
/* Defined in SDL_win32_main.c for Win32 */ /* Defined in SDL_win32_main.c for Win32 */
extern struct sdlfuncs sdl; extern struct sdlfuncs sdl;
extern SDL_sem *sdl_exit_sem; extern SDL_sem *sdl_exit_sem;
extern int sdl_video_initialized;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment