Strange SDL_GetTicks() behaviour

Hi,

I am trying to use SDL_GetTicks() to get the current time since SDL initialisation by storing it in a variable that is updated in the Game Loop draw() function. It acts strangely and I don’t know exactly why. (I am using VS2015)

The variable CurrentTime (data type uint32) stores the GetTicks(); value, divided by 1000 (to get seconds). I have it stored in the Watch tab.

When I first launch the debugger and then break all after, say, 5 seconds, the variable counts correctly and displays 5s in the Watch tab. However, if I then continue, and then break all again, The value seems to have incremented 10-fold over the same time period.

Is there a reason why this happens?

Thanks :slight_smile:

However, if I then continue, and then break all again, The value seems to have incremented 10-fold over the same time period.

To be clear, SDL_GetTicks() returns the number of milliseconds since SDL_Init() was called, and it does not stop counting while you are paused at a breakpoint. Is that what you were seeing, or is it really just going wild beyond that?

Oh I did not know that. That would explain this strange behaviour :slight_smile:
I would ask how that works but it’s probably a bit technical for me.

Thanks :slight_smile:

I would ask how that works

It checks the clock maintained by the operating system itself, not one maintained by your app, whenever you call SDL_GetTicks().