From e08391080b5d47a585de64823e862860ce3ae03f Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 29 Sep 2012 13:14:31 -0500 Subject: [PATCH] SDL is now fully shut down with the RPi renderer. --- changelog.txt | 3 +++ src/Renderer_init_rpi.cpp | 28 ++++++++++++++++++++++++++++ src/main.cpp | 22 +--------------------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/changelog.txt b/changelog.txt index 9ed5efe80..415a676cb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +September 29 +-SDL is now completely shut down on both the RPi and SDL GL renderer. You may see the flicker of a terminal when you launch a game. This was done in preparation for audio. + September 23 -Fixed crash when "%ROM%" isn't present in a launch command. Not sure why you'd ever do this on purpose, but hey. -Added relative path operator ("./") support for gamelist.xml, for both game paths and image paths. diff --git a/src/Renderer_init_rpi.cpp b/src/Renderer_init_rpi.cpp index 386789444..da0519e4f 100644 --- a/src/Renderer_init_rpi.cpp +++ b/src/Renderer_init_rpi.cpp @@ -6,9 +6,13 @@ #include #include #include "Font.h" +#include +#include "InputManager.h" namespace Renderer { + SDL_Surface* sdlScreen; + EGLDisplay display; EGLSurface surface; EGLContext context; @@ -24,6 +28,26 @@ namespace Renderer bool createSurface() //unsigned int display_width, unsigned int display_height) { + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) + { + std::cerr << "Error initializing SDL!\n"; + std::cerr << SDL_GetError() << "\n"; + std::cerr << "Are you in the 'video' and 'input' groups? Is X closed? Is your firmware up to date? Are you using at least the 192/64 memory split?\n"; + return false; + } + + sdlScreen = SDL_SetVideoMode(1, 1, 0, SDL_SWSURFACE); + if(sdlScreen == NULL) + { + std::cerr << "Error creating SDL window for input!\n"; + return false; + } + + //have to reload config to re-open SDL joysticks + InputManager::loadConfig(); + + + std::cout << "Creating surface..."; DISPMANX_ELEMENT_HANDLE_T dispman_element; @@ -148,6 +172,10 @@ namespace Renderer void destroySurface() { + SDL_FreeSurface(sdlScreen); + sdlScreen = NULL; + SDL_Quit(); + eglSwapBuffers(display, surface); eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(display, surface); diff --git a/src/main.cpp b/src/main.cpp index f20f20ea6..cc5cb94cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,27 +71,7 @@ int main(int argc, char* argv[]) bool running = true; - //desktop uses SDL to set up an OpenGL context, and has its own SDL window...so I #ifdefed here. - //this should be moved to the RPi init/deinit file - - //ALWAYS INITIALIZE VIDEO. It starts SDL's event system, and without it, input won't work. - #ifdef _RPI_ - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) - { - std::cerr << "Error - could not initialize SDL!\n"; - std::cerr << " " << SDL_GetError() << "\n"; - std::cerr << "Are you in the 'video' and 'input' groups? Are you running with X closed? Is your firmware up to date? Are you using at least the 192/64 memory split?\n"; - return 1; - } - - SDL_Surface* sdlScreen = SDL_SetVideoMode(1, 1, 0, SDL_SWSURFACE); - if(sdlScreen == NULL) - { - std::cerr << "Error initializing SDL screen!\n"; - running = false; - } - #endif - + //the renderer also takes care of setting up SDL for input bool renderInit = Renderer::init(width, height); if(!renderInit) {