initializing a SDL_Event causes a texture not to be drawn

after initializing SDL_Event, the background image wont render. but commenting out the parts related to event renders everything as expected, what am i doing wrong?

 55         int i = 1;
 56         SDL_Event event;
 57         while(i == 1) {
 58                 while (SDL_PollEvent(&event)) {
 59                         switch (event.type) {
 60                                 case SDL_QUIT:
 61                                         i = 2;
 62                                 default:
 63                                         continue;
 64                                 }
 65                         }
 66                 f_r.x -= 10;
 67                 if (f_r.x < 10) {f_r.x = 1200;}
 68                 bg_r.x -=2;
 69                 if (bg_r.x < -1200) {bg_r.x = 0;}
 70                 SDL_RenderClear(renderer);
 71                 SDL_RenderCopy(renderer, bg_tex, NULL, &bg_r); // <- this does not render
 72                 SDL_RenderCopy(renderer, fire_tex, NULL, &f_r); // <- this works
 73                 SDL_RenderCopy(renderer, tex, NULL, &player); // ,<- this works 
 74                 SDL_RenderPresent(renderer);
 75                 SDL_Delay(16);
 76
 77         }

Try removing these two lines, they are not necessary and are probably causing it to loop continuously in the while statement:

    default:
            continue;

That did not change anything, also i dont think its stuck in the while loop since everything other than the background renderer is works as expected.

I would check that the bg_tex texture is valid and also that the bg_r contains correct values.
The x field is being set in the while loop but check that the y, w and h fields are valid too. I have sometimes made the mistake by not setting the w and h fields correctly, which has ended up having a rect of (0, 0) in size, which, together with that rect, won’t render anything.

they are fine, fwiw everything works fine when i remove out the event loop like this

          while(i == 1) {                
                  f_r.x -= 10;
                  if (f_r.x < 10) {f_r.x = 1200;}
                  bg_r.x -=2;
                  if (bg_r.x < -1200) {bg_r.x = 0;}
                  SDL_RenderClear(renderer);
                  SDL_RenderCopy(renderer, bg_tex, NULL, &bg_r);
                  SDL_RenderCopy(renderer, fire_tex, NULL, &f_r);
                  SDL_RenderCopy(renderer, tex, NULL, &player);
                  SDL_RenderPresent(renderer);
                  SDL_Delay(16);
 
          }

and when i initialize SDL_Event like this, it does not render the background

          SDL_Event event;
          while(i == 1) {                
                  f_r.x -= 10;
                  if (f_r.x < 10) {f_r.x = 1200;}
                  bg_r.x -=2;
                  if (bg_r.x < -1200) {bg_r.x = 0;}
                  SDL_RenderClear(renderer);
                  SDL_RenderCopy(renderer, bg_tex, NULL, &bg_r);
                  SDL_RenderCopy(renderer, fire_tex, NULL, &f_r);
                  SDL_RenderCopy(renderer, tex, NULL, &player);
                  SDL_RenderPresent(renderer);
                  SDL_Delay(16);
 
          }

It seems there’s something wrong on outside of your snippet. Have you fixed all of compiler warnings?

… and have you checked SDL_RenderCopy succeeded? You can check this with SDL_GetError() :

printf("1: %s\n", SDL_GetError());
SDL_RenderClear(renderer);
printf("2: %s\n", SDL_GetError());
SDL_RenderCopy(renderer, bg_tex, NULL, &bg_r); // <- this does not render
printf("3: %s\n", SDL_GetError());
SDL_RenderCopy(renderer, fire_tex, NULL, &f_r); // <- this works
printf("4: %s\n", SDL_GetError());
SDL_RenderCopy(renderer, tex, NULL, &player); // ,<- this works 
printf("5: %s\n", SDL_GetError());
SDL_RenderPresent(renderer);

(of course, you can do this more wisely; SDL_RenderPresent will return non-zero value when it failed.)

You should still leave out the continue statement, since it’s not needed, and replace it with break or leave out the default case entirely. It would only be useful if you had some additional code after the switch statement in the while loop that you wanted to skip. As your code currently stands, there’s nothing after the switch block, so it jumps back up to the top of that while loop anyway.

As to the rest of it, if simply adding one variable (the SDL_Event) breaks your code then you might have stack corruption. Are you sure bg_tex and bg_r are valid with the SDL_Event?

Also, why are you calling SDL_Delay()? If you want vertical sync, create your renderer with the SDL_RENDERER_PRESENTVSYNC flag, since that will make it hook into the OS’s hooks for syncing up with the display. SDL_Delay() guarantees only that it will delay for at least that much time; it could delay for a lot longer.