Problem with SDL_GetTicks


I’m developping under SDL2 ( On Linux ),

First, to follow what that I will say:
I created a struct TileMap, this struct ( with my algorithm ) create a 2D map of 20x20 blocks ( each block is 32x32 px )

So, I have a problem using the SDL_GetTicks:
I created a variable: “int currTime = 0;”
In my main while, at the begin, I do: “currTime = SDL_GetTicks();”,

I don’t have any problems during the compiling, but when I’m running the output file ( “./a.out” ), my 32 firsts pixels are not displayed with my texture, but with the default color of my background ( white in fact ).

So, for resume: my first line of TileMap is remplace by the color of my background…

I’m sure that is SDL_GetTicks the problem because I tried to remove line by line the code that I added, and when I’m removing the “currTime = SDL_GetTicks();” line, the problem disappears… I also tried to move this line to the end of my while loop, but the problem is still here…

What is the problem ? Why do I have this ?

( P.S: I already had a similar problem with some other lines, but that was because I do an error on these line, but here, I follow a tutorial on YouTube for handling FPS… )

Sorry for my english, I’m french…



I have to do a modification of what I said:

Following the SDL Wiki, I retried:
At the end of my main while loop, if I just let: “currTime = SDL_GetTicks();” the problem disappears, but if I create a “if” condition just after this line, the problem come back again…

In my “if” block, if I put: “if(currTime > lastTime + 1000)” ( as on the wiki ), the problem come back.
But, if I do: “if(1 == 1)” ( for testing ) the problem disappears…


Sorry, but it’s a bit hard to understand what exactly it is you’re trying to do.

Do you have issues rendering your tilemap or do you have issues with moving one/multiple object(s) based on the framerate/FPS? Or maybe both issues?

Regardless of the issue(s) you’re having with your code/game/application, it’s always good to show some code and someone here might be able to spot some error(s) in it.

Hi Daniel1985,

Sorry for the long time for my reply,

I will try to explain you my problem exactly:
When I put the line of code: “currTime = SDL_GetTicks();” ( so to get the current time, based on the SDL Wiki ), my window render a line of SCREEN_WIDTHx32 px in white ( = 704x32 px )

I know that hard to represent with words, so this is my code:
( I put main.c and headers.h on a GitHub repository because I can’t upload here because I’m new… )
This is my repository

So please check the code ( The comments are in french, sorry lol )

The SDL_GetTicks() is in the while(isRunning) at his end.

I compile my code like this: "cc main.c sdl2-config --cflags --libs" ( I’m on linux )

The code that I put in this repository is without the bug.
If you wanna see the bug, just un-comment lines 174 and 175 ( the if statement )



I can sadly not re-create the bug you describe. When I run the application, with line 174 and 175 enabled, no visual bug occur.

See screenshot below:

Whatttt ?

Seriously ? Wow…

Look for me ( With lines 174 and 175 enabled ):
( I can’t upload files… So this is the link )

You see the white band at the top, this is my problem…
I think you tried to do somethings when the window is open, you can click on the green squares with the black dot at his middle. Me, with the white band, I can’t click the first one ( at the top-left corner )

So there is no bug for you ? But why I have this bug…

I’m under Kali Linux 2020, and I don’t have access to a Windows, so I can’t code under Windows, but do you think the problem is Linux ? And if it is, there is a solution ?