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
Collecting input from an external window
Mako_energy


Joined: 10 Feb 2011
Posts: 46
This thread is just continuing from another thread I made a while back. I've done a bunch of various fixes and updates to my engine, and now I'm coming back to the graphics subsystem. Here's the previous thread:

http://forums.libsdl.org/viewtopic.php?t=7426

What I am mostly concerned about right now, is knowing whether or not what I want to do is possible. What I want to do is create a window in Ogre, that is Ogre's responsibility to maintain(when it comes to buffer swaps and creating/handling the render context, etc.) and have SDL simply build it's own window/input structures around it allowing it to collect input from it. I'm currently trying to do this with "SDL_CreateWindowFrom()" function. I've attempted this once before(as stated in my previous thread) and it didn't crash immediately which I was impressed with, but it didn't generate any input events so that was a no-go. I tried tinkering with the input grab settings and anything else relating to input from a window to no avail. So if there is a fix, I'm guessing it's not simple/obvious.
Mako_energy


Joined: 10 Feb 2011
Posts: 46
I just recently found out that Ogre won't attempt to set FullScreen Anti-Aliasing settings unless it has control over the window made. So I've gone from preferring this approach to needing this approach.

Someone out there has to know how this can be accomplished. I would greatly appreciate any help.
Collecting input from an external window
René Dudfield
Guest

It sounds like you'd need to write an ogre backend for SDL for that to work.

On Tue, Sep 27, 2011 at 10:11 PM, Mako_energy wrote:
Quote:
I just recently found out that Ogre won't attempt to set FullScreen Anti-Aliasing settings unless it has control over the window made. So I've gone from preferring this approach to needing this approach.

Someone out there has to know how this can be accomplished. I would greatly appreciate any help.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Mako_energy


Joined: 10 Feb 2011
Posts: 46
I hope not. =\ I've seen other posts (on this forum as well as others) that have hinted it can work without large amounts of extra code.

I've been tinkering with this a bit more and found out quite a bit regarding this issue. First it turned out that I wasn't actually properly initializing the SDL video subsystem due to some twisted logic in my code base, that has since been corrected. Next was getting crashes that seemed to be a result of a failed call to SetProp() (windows api) when constructing the window. I found out that was because of differences in how the window handle was passed around between SDL and Ogre. In short, I had to create an HWND myself, pass it in by reference when getting the handle from ogre, and then pass it in as is to SDL. So before it wasn't getting the valid HWND, hence the crash.

Now...I have another issue and I am not entirely sure how to fix it, although I'm sure it is something I did wrong. When I try to create a window with SDL_CreateWindowFrom() it goes down the chain of functions normally until it gets to line 169 of SDL_WindowsWindow.c. Looks like this:

Code:
SDL_SetKeyboardFocus(data->window);


When it calls that line of code the debugger jumps instead to "WIN_StartTextInput()", and promptly crashes when it attempts to dereference the driverdata pointer in that function. I immediately suspected some mismatch between the headers and the library, so I deleted all my headers of SDL, and SDL.dll. I updated my repo to the most recent version (wasn't many updates cause I did this yesterday as well) and removed all local changes when I applied the update, just in case. I then recompiled SDL, and copied the include folder in the repo to my project as well as the fresh SDL.dll. It is still crashing.

I'm still going to tinker with this since it's probably something dumb and simple, but if anyone has an idea in the mean time I'd appreciate the help.
Collecting input from an external window
Jonny D


Joined: 12 Sep 2009
Posts: 932
Is your goal just to get Ogre to work with SDL 1.3?  I've not tried, but I'll provide moral support for now.

Jonny D


On Wed, Sep 28, 2011 at 6:52 PM, Mako_energy wrote:
Quote:
I hope not. =\ I've seen other posts (on this forum as well as others) that have hinted it can work without large amounts of extra code.

I've been tinkering with this a bit more and found out quite a bit regarding this issue. First it turned out that I wasn't actually properly initializing the SDL video subsystem due to some twisted logic in my code base, that has since been corrected. Next was getting crashes that seemed to be a result of a failed call to SetProp() (windows api) when constructing the window. I found out that was because of differences in how the window handle was passed around between SDL and Ogre. In short, I had to create an HWND myself, pass it in by reference when getting the handle from ogre, and then pass it in as is to SDL. So before it wasn't getting the valid HWND, hence the crash.

Now...I have another issue and I am not entirely sure how to fix it, although I'm sure it is something I did wrong. When I try to create a window with SDL_CreateWindowFrom() it goes down the chain of functions normally until it gets to line 169 of SDL_WindowsWindow.c. Looks like this:




Code:

SDL_SetKeyboardFocus(data->window);




When it calls that line of code the debugger jumps instead to "WIN_StartTextInput()", and promptly crashes when it attempts to dereference the driverdata pointer in that function. I immediately suspected some mismatch between the headers and the library, so I deleted all my headers of SDL, and SDL.dll. I updated my repo to the most recent version (wasn't many updates cause I did this yesterday as well) and removed all local changes when I applied the update, just in case. I then recompiled SDL, and copied the include folder in the repo to my project as well as the fresh SDL.dll. It is still crashing.

I'm still going to tinker with this since it's probably something dumb and simple, but if anyone has an idea in the mean time I'd appreciate the help.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Mako_energy


Joined: 10 Feb 2011
Posts: 46
Yes, although technically I already had Ogre working with SDL 1.3. Originally I had it such that SDL created and managed the window, and Ogre just rendered to it. I now want to reverse those rolls, and have Ogre responsible for everything about the window except for input, which SDL is to handle.

I've looked all over google, maybe I'm just not using the right search terms because everyone seems to think the only thing that can cause a different function then the one mentioned in the code to be called is if there is a mismatch between the binary and headers. I've built clean 3 times now with no change whatsoever. I'll take all the moral support (or other forms of support) that I can get. =\
Mako_energy


Joined: 10 Feb 2011
Posts: 46
Ok, I once again have something meaningful to post. So it was exactly as I expected, something really dumb and simple in my config that I overlooked a few times that resulted in a mismatch between the includes and the library. So that has since been corrected. But...the exact same behavior persists, because as it turns out that although my callstack was lying to me, the function "WIN_StartTextInput()" is in fact called at the end of "SDL_SetKeyboardFocus()".

Just as before, when it attempts to dereference the driverdata pointer that hasn't yet been assigned to on line 190 of SDL_windowskeyboard.c. This promptly causes a crash. I'm thinking this is an SDL bug, since there is no opportunity in this chain of functions for driverdata to have been made valid, and there are no checks in place to prevent a crash like this.
Collecting input from an external window
MrOzBarry


Joined: 26 Jun 2010
Posts: 620
I was under the impression that you could only collect input from an SDL window, so what's the issue with SDL creating the window and using that in Ogre, rather than Ogre creating the window?

On Thu, Sep 29, 2011 at 12:31 PM, Mako_energy wrote:
Quote:
Ok, I once again have something meaningful to post. So it was exactly as I expected, something really dumb and simple in my config that I overlooked a few times that resulted in a mismatch between the includes and the library. So that has since been corrected. But...the exact same behavior persists, because as it turns out that although my callstack was lying to me, the function "WIN_StartTextInput()" is in fact called at the end of "SDL_SetKeyboardFocus()".

Just as before, when it attempts to dereference the driverdata pointer that hasn't yet been assigned to on line 190 of SDL_windowskeyboard.c. This promptly causes a crash. I'm thinking this is an SDL bug, since there is no opportunity in this chain of functions for driverdata to have been made valid, and there are no checks in place to prevent a crash like this.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Mako_energy


Joined: 10 Feb 2011
Posts: 46
I am creating an SDL window, just from a pre-created one that is not claiming any ownership over the windows input. Furthermore I can see that while it's trying to construct the window prior to the crash it is getting and setting the keyboard focus. So clearly it is doing something with input. Unless someone can tell me definitively that this will not work, I'm going to take this progress as encouragement and keep on trying.

As for why I want to do this change, a number of reasons. One of the biggest being code cleanliness. If I can get this to work I can cut the complications involved in sync'ing the two windows between SDL and Ogre quite substantially. Another big reason is that doing it this way eliminates the need for me to find an Objective-C/Cocoa developer to create the large and disgusting Mac binder we have yet to implement for our mac side. Which is kinda good since I've had a post up asking for help with that(and offering money) both here and on the Ogre forums for nearly two weeks now and no one has responded.

I'd really like to get a response to the issue raised in my previous post, because I think it's an SDL bug in which case I can't do much out of fear of breaking SDL.
Mako_energy


Joined: 10 Feb 2011
Posts: 46
I went on ahead and decided to wing it and alter the source code of SDL. I didn't see anything obvious that prohibited moving the assignment of "data" in "SetupWindowData()" further up(sooner) in the function. I ended up putting just after the call and check of "SetProp()", and commented out the assignment at the end of the function. Now it works perfectly. Ogre controls the window and input is being collected just as before.

I am still curious as to why that assignment was put there like that, with other functions that need the data sooner. I'd like to see that issue fixed so others don't have the same problem as I.
Collecting input from an external window
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
If you post a patch I can take a look at it and see if we can't just include it in SDL.

On Fri, Sep 30, 2011 at 5:05 PM, Mako_energy wrote:
Quote:
I went on ahead and decided to wing it and alter the source code of SDL. I didn't see anything obvious that prohibited moving the assignment of "data" in "SetupWindowData()" further up(sooner) in the function. I ended up putting just after the call and check of "SetProp()", and commented out the assignment at the end of the function. Now it works perfectly. Ogre controls the window and input is being collected just as before.

I am still curious as to why that assignment was put there like that, with other functions that need the data sooner. I'd like to see that issue fixed so others don't have the same problem as I.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Mako_energy


Joined: 10 Feb 2011
Posts: 46
Sam! Good to see you still around. It was a really simple change and I can't seem to post files here, so I'll just post the contents of the patch/diff file I generated.

Code:
97a98,99
>    
>    window->driverdata = data;
186c188
<     window->driverdata = data;
---
>     //window->driverdata = data;


I literally just commented out the data assignment at the end of "SetupWindowData()" in SDL_windowswindow.c, and moved it to just after the call to "SetProp()". Nothing more.

We're currently going through the process of getting our linux side caught up with the new binder, and we're worried the linux side may need a similar change(Mac as well when we get to it). If it does I'll post back about it.