Keyboard bug?

I’ve been trying to tease apart the event code, but
I’m having some trouble with keyboard events:

  1. the test program “checkkeys” works fine.

  2. so far, tracing through the keyboard event code,
    the keysyms seem correct when pushed into the queue.

  3. by the time I use SDL_PollEvent() to get the event,
    the scancode is intact, the value that should be in
    "key.keysym.sym" is in “key.keysym.mod”, and
    "key.keysym.sym" and “key.keysym.unicode” are zero…

I still need to formulate a minimum test case, but I
am open to any suggestions you can offer.

Thanks in advance,

-Loren__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

  1. by the time I use SDL_PollEvent() to get the event,
    the scancode is intact, the value that should be in
    "key.keysym.sym" is in “key.keysym.mod”, and
    "key.keysym.sym" and “key.keysym.unicode” are zero…

It sounds like structure packing is wrong in your code.

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

  1. by the time I use SDL_PollEvent() to get the event,
    the scancode is intact, the value that should be in
    "key.keysym.sym" is in “key.keysym.mod”, and
    "key.keysym.sym" and “key.keysym.unicode” are zero…

I still need to formulate a minimum test case, but I
am open to any suggestions you can offer.

Is this Linux? You might want to use Valgrind and/or ElectricFence to make
sure it’s not a memory corruption on your side, first.

Also, the Unicode field doesn’t get set if you didn’t explicitly enable
Unicode (not that this explains the rest of it).

Have we changed the SDL_Event structure recently? It might be a matter of
a header/library mismatch in such a case.

–ryan.

— Sam Lantinga wrote:

  1. by the time I use SDL_PollEvent() to get the
    event,
    the scancode is intact, the value that should be
    in
    "key.keysym.sym" is in “key.keysym.mod”, and
    "key.keysym.sym" and “key.keysym.unicode” are
    zero…

It sounds like structure packing is wrong in your
code.

Doh!.. You were right… well almost… It turned
out to be enum size, not struct packing, but the
suggestion got me reexamining my compiler arguments.
Is there anything we can do to check this at compile
time in the SDL headers so that other users don’t run
into this problem?

Perhaps something like:

enum SDL_Private_Test_Enum {
    SDL_Private_Test_A, SDL_Private_Test_B,
    SDL_Private_Test_C, SDL_Private_Test_D
};

struct SDL_Private_Test_Packing {
    uint8 a;
    uint16 b;
    uint8 c;
    uint16 d;
    uint32 e;
    uint16 f;
};

#if $(SIZE_OF_TEST_ENUM) != \
sizeof(SDL_Private_Test_Enum)
#error "Enum size incompatible with enum size

compiled into SDL library."
#endif

#if $(SIZE_OF_TEST_STRUCT) != \
sizeof(SDL_Private_Test_Packing)
#error "Struct packing or alignment incompatible

with packing and alignment compiled into SDL library."
#endif

where the $() variables would be expanded at SDL build
time. Enums and structs already in SDL would, of
course, work just as well. Just trying to avoid other
people having this problem. If it doesn’t compile,
they’ll know the problem sooner rather than later.

Just a thought.

Best wishes,

-Loren__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

Doh!.. You were right… well almost… It turned
out to be enum size, not struct packing, but the
suggestion got me reexamining my compiler arguments.
Is there anything we can do to check this at compile
time in the SDL headers so that other users don’t run
into this problem?

Great idea! Done!

Thanks,
-Sam Lantinga, Software Engineer, Blizzard Entertainment