Timing bug

i?ve found some weird behavior of SDL_GetTicks(). i initialize the
library with SDL_INIT_VIDEO and SDL_INIT_TIMER and use video mode setup,
keyboard event polling and SDL_GetTicks().
now i?ve got this array of 256 chars that represent the keystates and a
pointer to it somewhere in a class. when i don?t use SDL_getTicks()
everything works fine, if i do use that command, suddenly the pointer
seems broken and the values don?t correspond to the actual contetn of
the array any more.

has anyone vere expeirenced something similar?

i?ve found some weird behavior of SDL_GetTicks(). i initialize the
library with SDL_INIT_VIDEO and SDL_INIT_TIMER and use video mode setup,
keyboard event polling and SDL_GetTicks().
now i?ve got this array of 256 chars that represent the keystates and a
pointer to it somewhere in a class. when i don?t use SDL_getTicks()
everything works fine, if i do use that command, suddenly the pointer
seems broken and the values don?t correspond to the actual contetn of
the array any more.

what platform?
also a minimal example would help

Mattias Engdeg?rd wrote:

i?ve found some weird behavior of SDL_GetTicks(). i initialize the
library with SDL_INIT_VIDEO and SDL_INIT_TIMER and use video mode setup,
keyboard event polling and SDL_GetTicks().
now i?ve got this array of 256 chars that represent the keystates and a
pointer to it somewhere in a class. when i don?t use SDL_getTicks()
everything works fine, if i do use that command, suddenly the pointer
seems broken and the values don?t correspond to the actual contetn of
the array any more.

what platform?
also a minimal example would help

problem solved.
my character array is 256 bytes long, but i map keys directly to it
using the SDL constants. so, if i want to notify that the left cursor
key is being pressed, i?d set keys[SDLK_LEFT] = 1; alas, the SDL
constants don?t cover the values from 0 to 255 but exceed those values
(SDLK_LEFT is 277 or something), so i just experienced an invalid
pointer access. quite why this worked when i didn?t use SDL_getTicks(),
i don?t know.
is there any table in the documentation that lists all SDLK-constants by
chance?

regards

eik

is there any table in the documentation that lists all SDLK-constants by
chance?

SDL_keysym.h which also includes the constant SDLK_LAST

SDL/docs/html/sdlkey.htmlOn Sun, Mar 11, 2001 at 04:30:29PM +0100, Mattias Engdegard wrote:

is there any table in the documentation that lists all SDLK-constants by
chance?

SDL_keysym.h which also includes the constant SDLK_LAST


Martin

Bother, said Pooh as Ziggy’s circuits failed.

problem solved.
my character array is 256 bytes long, but i map keys directly to it
using the SDL constants. so, if i want to notify that the left cursor
key is being pressed, i?d set keys[SDLK_LEFT] = 1; alas, the SDL
constants don?t cover the values from 0 to 255 but exceed those values
(SDLK_LEFT is 277 or something), so i just experienced an invalid
pointer access. quite why this worked when i didn?t use SDL_getTicks(),
i don?t know.

Slight changes anywhere in code can have strange effects on buggy code
sometimes. I remember one time I had ‘extern variable’ in a header file.
Code compiled without errors or warnings, but a sizeof(variable) check I had
returned 2 normally, but 4 if I commented out some unrelated code. Finally
ended up realizing I forget to specify the type it should be (int).

Anyway, it’s probably a good idea to add some error checking to your code.
If you haven’t learned about asserts yet, it’s time you did. It can make the
job of debugging your code thousands of times easier, seriously. I’d say for
any experienced programmer, all bugs are due to faulty assumptions. In your
case, you just assumed the index was going to be in range of your array.
Unless you are 100% certain without a doubt that your assumption is correct,
and always will be until the end of time, don’t rely on your assumptions.
Assert them instead. :slight_smile: Just a little tip from an experienced programmer.

is there any table in the documentation that lists all SDLK-constants by
chance?

Not that I know of, however there is the header file SDL_keysym.h. Code is
usually more reliable than any docs anyway. What you probably want is the
SDLK_LAST enum value. Looks like it’s guarenteed to be one higher than the
highest key value.On Saturday 10 March 2001 16:08, you wrote: