OS X + SDL_SetEventFilter = Bus Error

I have encapsulated the SDL init/drawing into a separate class and
use it with my console app.

I’m trying to use dynamic resizing by doing this

void Graph::drawGraph()
{
SDL_Init(SDL_INIT_VIDEO); // initialize SDL
SDL_SetEventFilter(eventFilter);
SDL_SetVideoMode(WindowWidth,WindowHeight,0,
SDL_OPENGL | SDL_RESIZABLE);
SDL_WM_SetCaption(WindowName.c_str(),NULL);
bool done = false;
while(!done)
{
current_graph = this;
drawGLScene();
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_VIDEORESIZE)
{
WindowWidth = event.resize.w;
WindowHeight = event.resize.h;
SDL_SetVideoMode(event.resize.w,event.resize.h,
0,SDL_OPENGL|SDL_RESIZABLE);
}
}
}
SDL_Quit();
}

The event filter is declared as a static member(so that it can be used as
a callback, i tried just the same with glut and it worked).

static int eventFilter(const SDL_Event *e)
{
if(e->type == SDL_VIDEORESIZE)
{
SDL_SetVideoMode(e->resize.w,e->resize.h,
0,SDL_OPENGL | SDL_RESIZABLE);
current_graph->WindowWidth = e->resize.w;
current_graph->WindowHeight = e->resize.h;
current_graph->drawGLScene();
}
return 1;
}

The problem here is that the app fails with “Bus Error”. I’ve hunted it down to
the SDL_SetVideoMode call i.e. if I remove the call, it resizes successfully
but naturally it doesn’t draw what I need(although
it does draw because I call drawGLScene() from here).

Any idea what the problem is?

And just an additional question - is it normal that when I resize the
window it also gets centered?

The problem here is that the app fails with “Bus Error”.

Have you tried running it under the debugger?

And just an additional question - is it normal that when I resize the
window it also gets centered?

Nope, are you using SDL 1.2.13?

See ya!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Sam Lantinga wrote:

And just an additional question - is it normal that when I resize the
window it also gets centered?

Nope, are you using SDL 1.2.13?

As far as I know that is indeed normal, also in 1.2.13. IIRC
SDL_SetVideoMode() completely destroys and recreates the window, causing
it to be re-centered.

-Christian

Sam Lantinga <slouken devolution.com> writes:

The problem here is that the app fails with “Bus Error”.

Have you tried running it under the debugger?

Yes, as I see(I haven’t used SDL sources) it doesn’t crash in
SDL_SetVideoMode but after return 1…

What happens as I see it: when I use SDL_PollEvent then SDL_VIDEORESIZE
gets posted to internal queue only when the button is released - so no
dynamic resizing - is it intended behaviour? By resorting to
event filter I hack the code by catching all the SDL_VideoResize messages
and handling it on my own. Or maybe the eventFilter handler is in another
thread, and the thread with the main loop gets paused when dragging…
If I remove the call to SDL_SetVideoMode from eventFilter handler the
window gets redrawn but I see garbage outside the original window, if
I don’t use eventFilter at all then the window
just blanks during resizing.
What I actually want to do is that the window gets redrawn during
resizing - the way it’s done in glut
for example. Or is it intended that it doesn’t get redrawn?

And just an additional question - is it normal that when I resize the
window it also gets centered?

Nope, are you using SDL 1.2.13?

Yes, 1.2.13… I’ve built it unix way(autogen.sh configure make make install)
with --without-x --disable-x11-video

Yes, I’ve read that setVideoMode recreates the window that’s why it gets
centered so I thought it was default behaviour.

Maybe I should compile from SVN…> See ya!

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Sam Lantinga wrote:

And just an additional question - is it normal that when I resize the
window it also gets centered?

Nope, are you using SDL 1.2.13?

As far as I know that is indeed normal, also in 1.2.13. IIRC
SDL_SetVideoMode() completely destroys and recreates the window, causing
it to be re-centered.

I just tested it with testwm -resize and it didn’t recenter the window
during or after resize… ?

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

What happens as I see it: when I use SDL_PollEvent then SDL_VIDEORESIZE
gets posted to internal queue only when the button is released - so no
dynamic resizing - is it intended behaviour? By resorting to
event filter I hack the code by catching all the SDL_VideoResize messages
and handling it on my own. Or maybe the eventFilter handler is in another
thread, and the thread with the main loop gets paused when dragging…

Yes, I believe the documentation states that you should never call SDL
video API functions from the event filter thread. It may be called from
another thread or from a hardware interrupt.

Instead you should either send another SDL event or set a global variable
or use some other messaging system to notify anyone who cares.

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Sam Lantinga <slouken devolution.com> writes:

I just tested it with testwm -resize and it didn’t recenter the window
during or after resize… ?

-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

I’ve asked around, it doesn’t recenter on win32 and linux it seems.
Have you tested on mac?

Sam Lantinga <slouken devolution.com> writes:

Yes, I believe the documentation states that you should never call SDL
video API functions from the event filter thread. It may be called from
another thread or from a hardware interrupt.

Instead you should either send another SDL event or set a global variable
or use some other messaging system to notify anyone who cares.

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

I think that’s what I get from using code hacks :wink:

So is there a standard way to do dynamic resizing(redrawing during resize)?

I’ve asked around, it doesn’t recenter on win32 and linux it seems.
Have you tested on mac?

Yes, the testwm test program with the -resize option on Mac OS X 10.5.1

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Sam Lantinga wrote:

As far as I know that is indeed normal, also in 1.2.13. IIRC
SDL_SetVideoMode() completely destroys and recreates the window, causing
it to be re-centered.

I just tested it with testwm -resize and it didn’t recenter the window
during or after resize… ?

You’re right, it only does that in OpenGL mode (and a few other special
cases). See SDL_QuartzVideo.m:666. I missed that because the OpenGL case
is the only one I’m familiar with.

-Christian

Christian Walther <cwalther gmx.ch> writes:

I just tested it with testwm -resize and it didn’t recenter the window
during or after resize… ?

You’re right, it only does that in OpenGL mode (and a few other special
cases). See SDL_QuartzVideo.m:666. I missed that because the OpenGL case
is the only one I’m familiar with.

-Christian

Hm, but if I don’t change the GL attributes, can I force it not to be destroyed?
Apart from hacking the source code of SDL :slight_smile:

Sam Lantinga wrote:

Yes, the testwm test program with the -resize option on Mac OS X 10.5.1

Congratulations for the baby Sam, we all hope she’ll be the SDL 3.0
maintainer, look at where I’ve found this news :slight_smile:


Bye,
Gabry

PS: Sorry for the OT :slight_smile:

Hello !

Congratulations for the baby Sam, we all hope she’ll be the SDL 3.0
maintainer, look at where I’ve found this news :slight_smile:

http://www.wowinsider.com/2008/01/08/congrats-to-blizzards-slouken-on-a-new-baby/

:slight_smile:

CU