Jump to content
  • Advertisement
Sign in to follow this  

SDL and Ogre3D not shutting down cleanly

This topic is 1414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I currently open an SDL window (without creating an OpenGL context) and have Ogre3D render to SDL's window. This works until shutdown, that's when the following error occurs:

*-*-* OGRE Shutdown
Unregistering ResourceManager for type Compositor
Unregistering ResourceManager for type Skeleton
Unregistering ResourceManager for type Mesh
Unregistering ResourceManager for type HighLevelGpuProgram
Uninstalling plugin: GL RenderSystem
Unregistering ResourceManager for type GpuProgram
*** Stopping GLX Subsystem ***
Unregistering ResourceManager for type Texture
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  4 (X_DestroyWindow)
  Resource id in failed request:  0x6c00002
  Serial number of failed request:  21
  Current serial number in output stream:  23
Here is the code for initialising Ogre3D:

RenderSystem::RenderSystem() :
    m_Root(new Ogre::Root("","","Ogre.log")),
    // The idea here is to open an SDL window *without* creating a GL context
    // and let Ogre create its own GL context, since it seems to be a little
    // sensitive when given an external one.
    // Ogre can be instructed to render to an external window, namely the one
    // SDL created.
    // TODO get window width and height from somewhere (config file?)
    unsigned int windowWidth = 800;
    unsigned int windowHeight = 600;
    // Create SDL Window without OpenGL context
    m_Window = SDL_CreateWindow( "Window",
                                 SDL_WINDOWPOS_CENTERED|SDL_WINDOW_RESIZABLE // TODO Add window resize support
    // Prepare Ogre render window parameters
    Ogre::NameValuePairList lParams;
    lParams["FSAA"] = "0";
    lParams["vsync"] = "true";
    lParams["macAPI"] = "carbon";
    // Get SDL window handle and insert into parameter list so ogre knows which
    // external window to use.
    SDL_SysWMinfo info;
    SDL_GetWindowWMInfo( m_Window, &info );
    size_t winHandle = reinterpret_cast<size_t>(info.info.win.window);
    lParams["externalWindowHandle"] = Ogre::StringConverter::toString(winHandle);
    size_t winHandle = reinterpret_cast<size_t>(info.info.x11.window);
    lParams["parentWindowHandle"] = Ogre::StringConverter::toString(winHandle);
#   error Defined OGRE_PLATFORM not supported
    // Load the GL Rendersystem and set up
    Ogre::String renderer = "./RenderSystem_GL";
    m_Root->loadPlugin( renderer );
    Ogre::RenderSystem* renderSystem = m_Root->getAvailableRenderers()[0];
    // Initialise ogre to use the SDL window
    m_Root->initialise( false, "", "" );
    m_RenderWindow = m_Root->createRenderWindow( "Window", windowWidth, windowHeight, false, &lParams );
Here is the code for shutting down:

    // Shut down ogre
    m_Root->destroySceneManager( m_SceneMgr );
    delete m_Root;
I'm running on Ubuntu, Linux and am using g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2.

Share this post

Link to post
Share on other sites
Why are you using both SDL and Ogre3d? Ogre3d already has its own window system. In Windows, every widget and window can store one pointer to userdata. It's possible that both libraries are attempting to set its own user data on the win32 window, which would explain the "invalid window parameter" error.

Share this post

Link to post
Share on other sites
Why are you using both SDL and Ogre3d?



I'm using SDL's input event system, because Ogre3D doesn't handle input. 


Could it be that Ogre is destroying the SDL window even though it shouldn't?

Share this post

Link to post
Share on other sites

That is exactly what is happening! Same thing happened to me.


Here's my startup code:

bool init()
    mRoot.reset(new Ogre::Root(plugins_cfg));
    if ( !mRoot->showConfigDialog() ) {
    	// User cancelled.
    	return false;

    Ogre::RenderWindow* mWindow = mRoot->initialise(true);
    if ( mWindow == nullptr ) {
	std::cerr << "Window could not be initialized." << std::endl;
	return false;
    size_t window_handle = 0;
    mWindow->getCustomAttribute("WINDOW", &window_handle);
    if ( !SDL_CreateWindowFrom( (void*)window_handle ) ) {
	std::cerr << SDL_GetError() << std::endl;
	return false;

The getCustomAttribute method of the root literally says that this is a hacky way of doing this, but I think it's pretty solid. To quit now, all you need to do is call SDL_Quit().


When you destroy the root, the root deletes all of its components, including the RenderWindow.

Edited by status_quo69

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!