mirror of https://github.com/stella-emu/stella.git
Specifically initialize and quit each SDL subsystem.
- Now video/timer and joystick subsystems are opened and closed in the proper SDL2 way - SDL_Quit() is also done at the very end, to clean up any remaining SDL state - Hopefully this fixes the issues with RPi not exiting cleanly.
This commit is contained in:
parent
bf8b0b3a88
commit
2b3e2dc385
|
@ -22,6 +22,22 @@
|
|||
EventHandlerSDL2::EventHandlerSDL2(OSystem& osystem)
|
||||
: EventHandler(osystem)
|
||||
{
|
||||
#ifdef JOYSTICK_SUPPORT
|
||||
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
|
||||
{
|
||||
ostringstream buf;
|
||||
buf << "ERROR: Couldn't initialize SDL joystick support: " << SDL_GetError() << endl;
|
||||
osystem.logMessage(buf.str(), 0);
|
||||
}
|
||||
osystem.logMessage("EventHandlerSDL2::EventHandlerSDL2 SDL_INIT_JOYSTICK", 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
EventHandlerSDL2::~EventHandlerSDL2()
|
||||
{
|
||||
if(SDL_WasInit(SDL_INIT_JOYSTICK))
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -215,6 +231,6 @@ EventHandlerSDL2::JoystickSDL2::JoystickSDL2(int idx)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
EventHandlerSDL2::JoystickSDL2::~JoystickSDL2()
|
||||
{
|
||||
if(myStick)
|
||||
if(SDL_WasInit(SDL_INIT_JOYSTICK) && myStick)
|
||||
SDL_JoystickClose(myStick);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class EventHandlerSDL2 : public EventHandler
|
|||
Create a new SDL2 event handler object
|
||||
*/
|
||||
explicit EventHandlerSDL2(OSystem& osystem);
|
||||
virtual ~EventHandlerSDL2() = default;
|
||||
virtual ~EventHandlerSDL2();
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
|
|||
myRenderer(nullptr)
|
||||
{
|
||||
// Initialize SDL2 context
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) < 0)
|
||||
if(SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
|
||||
{
|
||||
ostringstream buf;
|
||||
buf << "ERROR: Couldn't initialize SDL: " << SDL_GetError() << endl;
|
||||
|
@ -72,6 +72,7 @@ FrameBufferSDL2::~FrameBufferSDL2()
|
|||
SDL_DestroyWindow(myWindow);
|
||||
myWindow = nullptr;
|
||||
}
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -124,6 +124,11 @@ class MediaFactory
|
|||
return make_unique<EventHandlerSDL2>(osystem);
|
||||
}
|
||||
|
||||
static void cleanUp()
|
||||
{
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
MediaFactory() = delete;
|
||||
|
|
|
@ -57,6 +57,8 @@ int main(int argc, char* argv[])
|
|||
auto Cleanup = [&theOSystem]() {
|
||||
theOSystem->logMessage("Cleanup from main", 2);
|
||||
theOSystem->saveConfig();
|
||||
theOSystem.reset(); // Force delete of object
|
||||
MediaFactory::cleanUp(); // Finish any remaining cleanup
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue