Init SDL2 before Qt4 to avoid crash on Linux (bug #4529)

pull/540/head
Andrei Kortunov 6 years ago
parent a9729878d7
commit 2b90504558

@ -1,6 +1,7 @@
set(LAUNCHER
datafilespage.cpp
graphicspage.cpp
sdlinit.cpp
main.cpp
maindialog.cpp
playpage.cpp
@ -19,6 +20,7 @@ set(LAUNCHER
set(LAUNCHER_HEADER
datafilespage.hpp
graphicspage.hpp
sdlinit.hpp
maindialog.hpp
playpage.hpp
textslotmsgbox.hpp

@ -12,7 +12,6 @@
#define MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
#endif // MAC_OS_X_VERSION_MIN_REQUIRED
#include <SDL.h>
#include <SDL_video.h>
#include <components/files/configurationmanager.hpp>
@ -48,27 +47,15 @@ Launcher::GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, Settings:
}
bool Launcher::GraphicsPage::connectToSdl() {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
SDL_SetMainReady();
// Required for determining screen resolution and such on the Graphics tab
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
return false;
}
signal(SIGINT, SIG_DFL); // We don't want to use the SDL event loop in the launcher,
// so reset SIGINT which SDL wants to redirect to an SDL_Quit event.
return true;
}
bool Launcher::GraphicsPage::setupSDL()
{
bool sdlConnectSuccessful = connectToSdl();
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
bool sdlConnectSuccessful = initSDL();
if (!sdlConnectSuccessful)
{
return false;
}
#endif
int displays = SDL_GetNumVideoDisplays();
@ -89,8 +76,10 @@ bool Launcher::GraphicsPage::setupSDL()
screenComboBox->addItem(QString(tr("Screen ")) + QString::number(i + 1));
}
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
// Disconnect from SDL processes
SDL_Quit();
quitSDL();
#endif
return true;
}

@ -7,6 +7,8 @@
#include <components/settings/settings.hpp>
#include "sdlinit.hpp"
namespace Files { struct ConfigurationManager; }
namespace Launcher
@ -37,11 +39,6 @@ namespace Launcher
QStringList getAvailableResolutions(int screen);
QRect getMaximumResolution();
/**
* Connect to the SDL so that we can use it to determine graphics
* @return whether or not connecting to SDL is successful
*/
bool connectToSdl();
bool setupSDL();
};
}

@ -12,11 +12,18 @@
#endif // MAC_OS_X_VERSION_MIN_REQUIRED
#include "maindialog.hpp"
#include "sdlinit.hpp"
int main(int argc, char *argv[])
{
try
{
// Note: we should init SDL2 before Qt4 to avoid crashes on Linux,
// but we should init SDL2 after Qt5 to avoid input issues on MacOS X.
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
initSDL();
#endif
QApplication app(argc, argv);
// Now we make sure the current dir is set to application path
@ -33,7 +40,14 @@ int main(int argc, char *argv[])
if (result == Launcher::FirstRunDialogResultContinue)
mainWin.show();
return app.exec();
int exitCode = app.exec();
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
// Disconnect from SDL processes
quitSDL();
#endif
return exitCode;
}
catch (std::exception& e)
{

@ -0,0 +1,25 @@
#include <signal.h>
#include <SDL.h>
#include <SDL_video.h>
bool initSDL()
{
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
SDL_SetMainReady();
// Required for determining screen resolution and such on the Graphics tab
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
return false;
}
signal(SIGINT, SIG_DFL); // We don't want to use the SDL event loop in the launcher,
// so reset SIGINT which SDL wants to redirect to an SDL_Quit event.
return true;
}
void quitSDL()
{
// Disconnect from SDL processes
SDL_Quit();
}

@ -0,0 +1,8 @@
#ifndef SDLINIT_H
#define SDLINIT_H
bool initSDL();
void quitSDL();
#endif
Loading…
Cancel
Save