Help with Mouse events on OSX

I am having a bizarre problem with mouse events in an application on OSX.

From first principles, the following trivial application compiles and runs just fine:

Code:
#include <stdlib.h>
#include “SDL.h”

int main(int argc, char *argv[])
{
SDL_Event e;
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, “Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
SDL_SetVideoMode(400, 400, 32, 0);
for(;:wink:
{
if(SDL_PollEvent(&e))
{
switch(e.type)
{
case SDL_MOUSEBUTTONDOWN:
printf(“click x: %d, y: %d\n”, e.button.x, e.button.y);
break;
case SDL_QUIT:
return 0;
}
}
}
return 0;
}

clicking in the square correctly reports back x and y.

BUT if I move this code into my application the mouse co-ordinates are not updated betwen clicks /unless/ the mouse is ‘dragged’, i.e. MOUSEMOTION events are correct.

The application is a large piece of code which is compiled and run on both Win32 and Linux/X11 without problem.

Even putting the above code fragment /immediately/ in the main() routine shows the same behaviour.

Please can anyone help me track down what I might be doing wrong?

Thanks!

I think your loop is suspicious. Try using while(SDL_PollEvent(&e)), so you
handle every event until the queue is empty.

Jonny DOn Wed, Oct 21, 2009 at 6:50 PM, dave.lawrence

wrote:

I am having a bizarre problem with mouse events in an application on OSX.

From first principles, the following trivial application compiles and runs
just fine:

Code:

#include
#include “SDL.h”

int main(int argc, char *argv[])
{
SDL_Event e;
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, “Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
SDL_SetVideoMode(400, 400, 32, 0);
for(;:wink:
{
if(SDL_PollEvent(&e))
{
switch(e.type)
{
case SDL_MOUSEBUTTONDOWN:
printf(“click x: %d, y: %d\n”, e.button.x, e.button.y);
break;
case SDL_QUIT:
return 0;
}
}
}
return 0;
}

clicking in the square correctly reports back x and y.

BUT if I move this code into my application the mouse co-ordinates are not
updated betwen clicks /unless/ the mouse is ‘dragged’, i.e. MOUSEMOTION
events are correct.

The application is a large piece of code which is compiled and run on both
Win32 and Linux/X11 without problem.

Even putting the above code fragment /immediately/ in the main() routine
shows the same behaviour.

Please can anyone help me track down what I might be doing wrong?

Thanks!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi Jonny,

Thanks for suggestion – just tried replacing IF with WHILE and no difference.

I wish I could post some simple code that shows the problem!

Hmm… I have no more suggestions (of course, now that I look at it,
you are already technically doing what I suggested). It works fine on
Windows and Linux? What version of Mac OSX are you using? What SDL
library version? Where did you get your SDL libs? What compiler do
you use?

Jonny DOn Thu, Oct 22, 2009 at 11:30 AM, dave.lawrence

wrote:

Hi Jonny,

Thanks for suggestion – just tried replacing IF with WHILE and no
difference.

I wish I could post some simple code that shows the problem!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

BUT if I move this code into my application the mouse co-ordinates
are not updated betwen clicks /unless/ the mouse is ‘dragged’, i.e.
MOUSEMOTION events are correct.
The application is a large piece of code which is compiled and run
on both Win32 and Linux/X11 without problem.

Do you use it in fullscreen or Windowed? Which version of SDL do you
use 1.2 or 1.3?
I can confirm Cocoa mouse handling is having a problems and we’re
trying to sort it out, see “[patch] Cocoa fullscreen mouse fix”.

Best regards,–
Adam Strzelecki | nanoant.com

Hi Adam,

This is windowed. SDL version 1.2.12. What I don’t understand is why the trivial stand-alone app works fine, but including in the large app makes it fail in this odd way. Full screen seems to work OK (although there are other problems working full screen nothing to do with mouse events) – the pointer position is continually and correctly reported though.

Hi Jonny,

Application is mature and being running on win32 and linux without problem for many years. OSX build is a new ‘target’.
OSX 10.5.8. SDL 1.2.12, compiled with gcc (darwin 4.0.1)

At this stage I’d welcome even some ideas on what to try to track this down – what could I have in the main application which is interacting with the SDL event process. Have I inadvertantly enabled some mode? or disabled something?
threads? dunno! I’m not aware of doing anything!

Cheers,

Jonny D wrote:> Hmm… I have no more suggestions (of course, now that I look at it,

you are already technically doing what I suggested). It works fine on
Windows and Linux? What version of Mac OSX are you using? What SDL
library version? Where did you get your SDL libs? What compiler do
you use?

Jonny D

On Thu, Oct 22, 2009 at 11:30 AM, dave.lawrence <@dave.lawrence> wrote:

Hi Jonny,

Thanks for suggestion – just tried replacing IF with WHILE and no
difference.

I wish I could post some simple code that shows the problem!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I am having a bizarre problem with mouse events in an application on
OSX.

From first principles, the following trivial application compiles
and runs just fine:

[…]

clicking in the square correctly reports back x and y.

BUT if I move this code into my application the mouse co-ordinates
are not updated betwen clicks /unless/ the mouse is ‘dragged’, i.e.
MOUSEMOTION events are correct.

The application is a large piece of code which is compiled and run
on both Win32 and Linux/X11 without problem.

Even putting the above code fragment /immediately/ in the main()
routine shows the same behaviour.

Please can anyone help me track down what I might be doing wrong?

It’s a bit difficult to decide that, since you only showed us an
example that does work. Apparently, something is different in your
application, and in order to uncover the cause for your problems, one
will have to study precisely those differences :).

How do you build your application, from command line or using XCode?
Are you linking to SDLmain, and including SDL.h in the file that has
main, so that the main function gets properly replaced by SDL’s custom
main on OS X?

Bye,
MaxAm 22.10.2009 um 00:50 schrieb dave.lawrence:

I believe there are known issues with mouse handling on Mac OS X in
1.2.12. I would recommend updating to SDL 1.2.14.

See ya!On Thu, Oct 22, 2009 at 9:46 AM, dave.lawrence

wrote:

Hi Adam,

This is windowed. SDL version 1.2.12. What I don’t understand is why the
trivial stand-alone app works fine, but including in the large app makes it
fail in this odd way. Full screen seems to work OK (although there are other
problems working full screen nothing to do with mouse events) – the pointer
position is continually and correctly reported though.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

I will try 1.2.14 and report back – thanks for you suggestion despite my incredibly vague ‘it doesn’t work’ query!