Key presses emit noise on OSX

I recently updated to 1.3 SVN rev 5441 (from 4444) and found that in
my application, pressing special keys like arrows, enter or backspace
would cause the OS to emit a sound. I have noticed this on both OSX
10.4 (ppc) and OSX 10.6 (x86). Looking through the changes to
SDL_cocoakeyboard.m, I found a suspicious change in revision 4741.
Reverting before that (to 4964) got rid of the noise. Conversely,
switching to 4741 brought the noise back.

The biggest surprise came when I tried some of the sdl test programs
(testgl, mostly but also others) and never experienced that noise, no
matter how much I punched the keyboard. I couldn’t see any difference
in they way that keyboard input is handled between my code and the
test programs. It’s basically the same in both:

while (SDL_PollEvent(&e))
{
switch (…)
}

One difference is that I never call SDL_Init, only SDL_InitSubSystem.
But adding SDL_Init (0); at the beginning of my code didn’t change
anything. Changing testgl to only use SDL_InitSubSystem didn’t change
anything either. However, adding SDL_StartTextInput() right after the
init in testgl produces the same noise when pressing non-printable
keys. This leads me to believe that for some reason, text input mode
is somehow active in my program, though I am not certain why. Adding a
preventive SDL_StopTextInput() right after SDL_Init(0) just causes a
segfault:

Thread 0 Crashed:
0 libSDL-1.3.0.dylib 0x02b44060 SDL_StopTextInput + 32
(SDL_video.c:3596)
1 _sdl.so 0x007ccb24 _sdl_LTX_main_init + 100 (linux.cc:52)
2 libadonthell_main.0.dylib 0x002b030c adonthell::app::init() +
1084 (adonthell.cc:259)
3 libadonthell_main.0.dylib 0x002b0378 main + 72 (main.cc:83)
4 worldtest 0x0000759c _start + 760
5 worldtest 0x000072a0 start + 48

Adding it after the video subsystem init no longer crashes the app,
but doesn’t help with the noise either.

So here’s the question: anyone else experiencing this issue? What
might cause it in my app (but not in the SDL sample apps)? Any ideas,
other than sticking with an older revision for now?

Kai

Hi,

The text input code is developed by me. But I haven’t followed its
development for a while.

I recently updated to 1.3 SVN rev 5441 (from 4444) and found that in
my application, pressing special keys like arrows, enter or backspace
would cause the OS to emit a sound. I have noticed this on both OSX
10.4 (ppc) and OSX 10.6 (x86). Looking through the changes to
SDL_cocoakeyboard.m, I found a suspicious change in revision 4741.
Reverting before that (to 4964) got rid of the noise. Conversely,
switching to 4741 brought the noise back.

[snip]

It will be really nice if you can provide a minimum sample that
can reproduce the same problem. I tried to made one but it does
not have the problem you described.

One difference is that I never call SDL_Init, only SDL_InitSubSystem.
But adding SDL_Init (0); at the beginning of my code didn’t change
anything. Changing testgl to only use SDL_InitSubSystem didn’t change
anything either. However, adding SDL_StartTextInput() right after the
init in testgl produces the same noise when pressing non-printable
keys. This leads me to believe that for some reason, text input mode
is somehow active in my program, though I am not certain why. Adding a
preventive SDL_StopTextInput() right after SDL_Init(0) just causes a
segfault:

Thread 0 Crashed:
0 ? libSDL-1.3.0.dylib ? ? ? ? ?0x02b44060 SDL_StopTextInput + 32
(SDL_video.c:3596)
1 ? _sdl.so ? ? ? ? ? ? ? ? ? ? 0x007ccb24 _sdl_LTX_main_init + 100 (linux.cc:52)
2 ? libadonthell_main.0.dylib ? 0x002b030c adonthell::app::init() +
1084 (adonthell.cc:259)
3 ? libadonthell_main.0.dylib ? 0x002b0378 main + 72 (main.cc:83)
4 ? worldtest ? ? ? ? ? ? ? ? ? 0x0000759c _start + 760
5 ? worldtest ? ? ? ? ? ? ? ? ? 0x000072a0 start + 48

The patch attached can be used to prevent this crash. Sam, will you
please include this patch into trunk?

Thanks for the reply!

It will be really nice if you can provide a minimum sample that
can reproduce the same problem. I tried to made one but it does
not have the problem you described.

Here is one. Compile with

g++ sdl-input-test.cc -o input_test `sdl-config --cflags --libs`

Some additional info that might be helpful. Right now I am using SDL
rev 5521 on OSX 10.4 PPC, compiled the UNIX way with ./autogen.sh,
configure, make and make install.

You’ll also see that our code is C++ and (for now) uses SDL 1.2
compatibility mode.

Having that said, running ./input-test, then pressing any
non-printable key one or more time will emit the sound.

Kai
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdl-input-test.cc
Type: application/octet-stream
Size: 1832 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20100118/d35be3ad/attachment.objOn Mon, Jan 18, 2010 at 10:47 AM, Jjgod Jiang wrote:

Hi,On Tue, Jan 19, 2010 at 3:03 AM, Kai Sterker <kai.sterker at gmail.com> wrote:

? ?g++ sdl-input-test.cc -o input_test sdl-config --cflags --libs

Some additional info that might be helpful. Right now I am using SDL
rev 5521 on OSX 10.4 PPC, compiled the UNIX way with ./autogen.sh,
configure, make and make install.

You’ll also see that our code is C++ and (for now) uses SDL 1.2
compatibility mode.

Having that said, running ./input-test, then pressing any
non-printable key one or more time will emit the sound.

Oh, that’s because you called SDL_EnableUNICODE(1); which will call
SDL_StartTextInput() subsequently. Just put SDL_StopTextInput();
after SDL_EnableUNICODE(1); should do the trick.

However, I don’t see anything particular need to be done during
SDL_EnableUNICODE(1), if you are just ignoring text input events.
At least in Mac OS X, the keyboard layout transformation will
use Unicode layout first. So I think you may want to try simply
comment out SDL_EnableUNICODE(1), then see if everything still
works (especially those non-Latin characters typed with your
keyboard).

Sorry the logic here is a little bit messy, I am kind of confused
what SDL_EnableUNICODE() is expected to behave too.

  • Jiang

I added a patch from Jiang to fix this, in revision 5523

Thanks!On Tue, Jan 5, 2010 at 1:41 PM, Kai Sterker <kai.sterker at gmail.com> wrote:

I recently updated to 1.3 SVN rev 5441 (from 4444) and found that in
my application, pressing special keys like arrows, enter or backspace
would cause the OS to emit a sound. I have noticed this on both OSX
10.4 (ppc) and OSX 10.6 (x86). Looking through the changes to
SDL_cocoakeyboard.m, I found a suspicious change in revision 4741.
Reverting before that (to 4964) got rid of the noise. Conversely,
switching to 4741 brought the noise back.

The biggest surprise came when I tried some of the sdl test programs
(testgl, mostly but also others) and never experienced that noise, no
matter how much I punched the keyboard. I couldn’t see any difference
in they way that keyboard input is handled between my code and the
test programs. It’s basically the same in both:

?while (SDL_PollEvent(&e))
?{
? ?switch (…)
?}

One difference is that I never call SDL_Init, only SDL_InitSubSystem.
But adding SDL_Init (0); at the beginning of my code didn’t change
anything. Changing testgl to only use SDL_InitSubSystem didn’t change
anything either. However, adding SDL_StartTextInput() right after the
init in testgl produces the same noise when pressing non-printable
keys. This leads me to believe that for some reason, text input mode
is somehow active in my program, though I am not certain why. Adding a
preventive SDL_StopTextInput() right after SDL_Init(0) just causes a
segfault:

Thread 0 Crashed:
0 ? libSDL-1.3.0.dylib ? ? ? ? ?0x02b44060 SDL_StopTextInput + 32
(SDL_video.c:3596)
1 ? _sdl.so ? ? ? ? ? ? ? ? ? ? 0x007ccb24 _sdl_LTX_main_init + 100 (linux.cc:52)
2 ? libadonthell_main.0.dylib ? 0x002b030c adonthell::app::init() +
1084 (adonthell.cc:259)
3 ? libadonthell_main.0.dylib ? 0x002b0378 main + 72 (main.cc:83)
4 ? worldtest ? ? ? ? ? ? ? ? ? 0x0000759c _start + 760
5 ? worldtest ? ? ? ? ? ? ? ? ? 0x000072a0 start + 48

Adding it after the video subsystem init no longer crashes the app,
but doesn’t help with the noise either.

So here’s the question: anyone else experiencing this issue? What
might cause it in my app (but not in the SDL sample apps)? Any ideas,
other than sticking with an older revision for now?

Kai


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

Oh, that’s because you called SDL_EnableUNICODE(1); which will call
SDL_StartTextInput() subsequently. Just put SDL_StopTextInput();
after SDL_EnableUNICODE(1); should do the trick.

Yes, that worked.

However, I don’t see anything particular need to be done during
SDL_EnableUNICODE(1), if you are just ignoring text input events.

Coming from SDL 1.2, we did ignore those. But testing more today
actually shows that this leads to problems well when text input
actually occurs.

It also seems that unlike with SDL 1.2, it is not possible to
permanently stay in text input mode, as that will get pretty noisy
otherwise.

At least I now know how to make everything work, so thanks a lot!

KaiOn Tue, Jan 19, 2010 at 3:49 AM, Jjgod Jiang wrote:

Hi,On Wed, Jan 20, 2010 at 4:59 AM, Kai Sterker <kai.sterker at gmail.com> wrote:

However, I don’t see anything particular need to be done during
SDL_EnableUNICODE(1), if you are just ignoring text input events.

Coming from SDL 1.2, we did ignore those. But testing more today
actually shows that this leads to problems well when text input
actually occurs.

It also seems that unlike with SDL 1.2, it is not possible to
permanently stay in text input mode, as that will get pretty noisy
otherwise.

Oh, the beeping noise is a bug. Now you can update to SVN revision
5523, then with your original code everything should be fine.

  • Jiang