The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Crash when calling SDL_CreateWindowFrom
Mako_energy


Joined: 10 Feb 2011
Posts: 46
I currently have an Ogre/SDL setup, and I'm trying change the way my windows in both libraries are bound from the old way (where SDL makes the window and I pass the handle into Ogre), into the new way available to me in SDL 1.3 (where I pass the window handle into SDL after Ogre makes it) since I am sure this will clean up a bunch of code and potentially fix some issues.

When I try to do this however, it crashes. Here is my initialization code:
Code:
OgreWindow = Ogre::Root::getSingleton().createRenderWindow(WindowCaption, Settings.RenderWidth, Settings.RenderHeight, Settings.Fullscreen, &Opts);
HWND Data = 0;
OgreWindow->getCustomAttribute("WINDOW",&Data);
SDLWindow = SDL_CreateWindowFrom(&Data);


This is on Windows in case you couldn't tell, btw. The first thing that seems to go wrong is when SDL calls "SetProp" in the Windows API, it returns false. Which then SDL begins to destruct the window, and it gets all the way to line 115 of SDL_windowsframebuffer.c before seg faulting when it tried to dereference the SDL window data pointer. Here is the code (in my version) where it does that:
Code:
void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
{
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;

    __if (data->mdc) {__
        DeleteDC(data->mdc);
        data->mdc = NULL;
    }


The line with the underscores is where it crashes(not because of the underscores, I added those for clarity Razz ). So far I've checked the HWND I'm passing in and it looks valid. I can also verify the window is being created visually just before the crash. I've also checked my Ogre log for any hints of the construction going wrong and found nothing. So I'm currently suspecting this is an issue on SDL's end. I have no idea where to go from here. Any help or insights would be greatly appreciated.
Mako_energy


Joined: 10 Feb 2011
Posts: 46
Update:
So it seems it matters whether or not you pass in a "size_t" rather then a "HWND". HWND causes a crash, but a size_t and everything is fine. Mind = Blown.

But now I have a new issue. It seems the Window isn't collecting any input. Did I seriously misunderstand how SDL_CreateWindowFrom() function works? Does that not allow it to collect input? Is there some other configuration I need to get it to start collecting input?

Edit:
Posted a new thread about this issue here.