Getting SDLK_UNKNOWN in keysym.sym

I’m using the standard win32 1.1.5 libs on Win2000 and Codewarrior 5.02.
Every key event I get only has SDLK_UNKNOWN in key.keysym.sym.
SDL_GetKeyState indicates that the proper key IS pressed, the scancode is
set properly, I just don’t get the SDLK. Help, please.
Btw, everything else is working fine. Mouse, video, cdrom, etc… Just this
one part is giving me trouble.

TIA

Scott

Just replying to myself with some additional info.

I’ve discovered that SDL_PollEvent is playing with memory outside the
SDL_Event structure. Specifically, it clears 20 bytes of memory, but my
compiler reports that SDL_Event is only 16 bytes. So the question begs to
be asked: how many bytes SHOULD this structure be?
I’m sure this is an issue with CodeWarrior. Surely someone else out there
has used SDL with it. I’d build the libraries myself, but I don’t have the
DX SDK.
The only thing I could think of trying was setting the packing alignment to
4 bytes, but it didn’t help. Anyone??

At 01:20 PM 11/10/2000 -0600, you wrote:>I’m using the standard win32 1.1.5 libs on Win2000 and Codewarrior 5.02.

Every key event I get only has SDLK_UNKNOWN in key.keysym.sym.
SDL_GetKeyState indicates that the proper key IS pressed, the scancode is
set properly, I just don’t get the SDLK. Help, please.
Btw, everything else is working fine. Mouse, video, cdrom, etc… Just
this one part is giving me trouble.

TIA

Scott

Nevermind. Sorry for the spam, people. I got it working.
Just in case anyone runs into this, make sure to treat enums as ints.

At 03:17 PM 12/10/2000 -0600, you wrote:>Just replying to myself with some additional info.

I’ve discovered that SDL_PollEvent is playing with memory outside the
SDL_Event structure. Specifically, it clears 20 bytes of memory, but my
compiler reports that SDL_Event is only 16 bytes. So the question begs to
be asked: how many bytes SHOULD this structure be?
I’m sure this is an issue with CodeWarrior. Surely someone else out there
has used SDL with it. I’d build the libraries myself, but I don’t have the
DX SDK.
The only thing I could think of trying was setting the packing alignment
to 4 bytes, but it didn’t help. Anyone??

At 01:20 PM 11/10/2000 -0600, you wrote:

I’m using the standard win32 1.1.5 libs on Win2000 and Codewarrior 5.02.
Every key event I get only has SDLK_UNKNOWN in key.keysym.sym.
SDL_GetKeyState indicates that the proper key IS pressed, the scancode is
set properly, I just don’t get the SDLK. Help, please.
Btw, everything else is working fine. Mouse, video, cdrom, etc… Just
this one part is giving me trouble.

TIA

Scott

I’ve discovered that SDL_PollEvent is playing with memory outside the
SDL_Event structure. Specifically, it clears 20 bytes of memory, but my
compiler reports that SDL_Event is only 16 bytes. So the question begs to
be asked: how many bytes SHOULD this structure be?

from a cursory look at SDL_events.h it should be 16 bytes (on a 32-bit
architecture). Exactly where in SDL_PollEvents does it clear 20 bytes?

Mattias Engdeg?rd wrote:

I’ve discovered that SDL_PollEvent is playing with memory outside the
SDL_Event structure. Specifically, it clears 20 bytes of memory, but my
compiler reports that SDL_Event is only 16 bytes. So the question begs to
be asked: how many bytes SHOULD this structure be?

from a cursory look at SDL_events.h it should be 16 bytes (on a 32-bit
architecture). Exactly where in SDL_PollEvents does it clear 20 bytes?

On a related note, I was reading the GTK-win32 mailing list, and they
have discovered that when compiling GTK with GCC (mingw32) you need to
add -fnative-struct to CFLAGS. Apparently this is a flag that was added
for mingw32 so that the default alignment method would match MSVC, and
is needed to make sure that the DLL’s you compile with GCC can be used
with MSVC, and vice versa.

Perhaps that flag should be added for SDL as well.

On a related note, I was reading the GTK-win32 mailing list, and they
have discovered that when compiling GTK with GCC (mingw32) you need to
add -fnative-struct to CFLAGS. Apparently this is a flag that was added
for mingw32 so that the default alignment method would match MSVC, and
is needed to make sure that the DLL’s you compile with GCC can be used
with MSVC, and vice versa.

In what ways does MSVC’s struct alignment/layout differ from GCC’s?

I’m not sure where in SDL_PollEvents the clear was happening, because as I
mentioned I can’t build SDL (don’t have the DX SDK). But I did get it
working by setting setting ‘treat enums as ints’. Now I’m getting the
proper SDLK value back. I also had to make sure alignment was set to 4
bytes, adding the following code to begin_code.h:

#ifdef MWERKS
#pragma pack(push,4)
#endif

and the appropriate pop to close_code.h. Interestingly enough, it’s exactly
the same pragma as MSVC uses. Well, I thought it was interesting.
And finally, sizeof reports that SDL_Event is 20 bytes under these
conditions. Since it seems to be working properly, I guess that’s how big
it’s supposed to be. Didn’t feel like going through and doing the byte
count/alignment manually :slight_smile:

At 02:15 PM 13/10/2000 +0200, you wrote:> >I’ve discovered that SDL_PollEvent is playing with memory outside the

SDL_Event structure. Specifically, it clears 20 bytes of memory, but my
compiler reports that SDL_Event is only 16 bytes. So the question begs to
be asked: how many bytes SHOULD this structure be?

from a cursory look at SDL_events.h it should be 16 bytes (on a 32-bit
architecture). Exactly where in SDL_PollEvents does it clear 20 bytes?

Mattias Engdeg?rd wrote:

On a related note, I was reading the GTK-win32 mailing list, and they
have discovered that when compiling GTK with GCC (mingw32) you need to
add -fnative-struct to CFLAGS. Apparently this is a flag that was added
for mingw32 so that the default alignment method would match MSVC, and
is needed to make sure that the DLL’s you compile with GCC can be used
with MSVC, and vice versa.

In what ways does MSVC’s struct alignment/layout differ from GCC’s?

I don’t know all the details, but it apparently at least affects
integer bitfields which follow elements that are shorter than an int.
GCC by default packs the bits into the next byte, whereas MSVC pads
out to the next 4 byte boundary first.

Apparently, -fnative-struct just means “duplicate the native compiler
semantics for struct packing” in gcc, and probably isn’t a bad idea to
use for any platform which has multiple compilers in common use.

In what ways does MSVC’s struct alignment/layout differ from GCC’s?

I don’t know all the details, but it apparently at least affects
integer bitfields which follow elements that are shorter than an int.
GCC by default packs the bits into the next byte, whereas MSVC pads
out to the next 4 byte boundary first.

bit fields are hard to get right even if the basic alignment restrictions
of the architecture are known. It’s usually best to fall back to
explicit shifting and masking if binary compatibility is at all important

Apparently, -fnative-struct just means “duplicate the native compiler
semantics for struct packing” in gcc, and probably isn’t a bad idea to
use for any platform which has multiple compilers in common use.

struct layout including bit field packing should be covered by the platform’s
ABI, either codified or current practice. Being a cross-compiler I think
gcc should use the ABI of the target platform

By the way, differences in bitfield layout should not affect the size
of SDL_Event, no bit fields there as far as I can see