SDL_GameControllerGetButton depends on polling events

Hi
In the code below if i uncomment lines 11 to 18 then my program starts working correctly,
i.e if i press ButtonA on my gamepad I can exit.
But when those lines are commented like they are right now, then gamepad doesn’t work.

why is that?
thanks in advance.

  1. #include <SDL2/SDL.h>

  2. #include “stdio.h”

  3. int main()

  4. {

  5. SDL_Init(SDL_INIT_GAMECONTROLLER);
    
  6. SDL_Window *Window = SDL_CreateWindow("Hello SDL", 50, 50, 500, 500, 0);
    
  7. if (SDL_IsGameController(0) == SDL_TRUE) {
    
  8.     SDL_GameController *Controller = SDL_GameControllerOpen(0);
    
  9.     while (1) {
    
  10.         /*
    
  11.         SDL_Event *Event = NULL; 
    
  12.         SDL_PollEvent(Event);
    
  13.         while (Event != NULL) {
    
  14.             if (Event->type == SDL_QUIT) {
    
  15.                 return 0;
    
  16.             }
    
  17.             SDL_PollEvent(Event);
    
  18.         }
    
  19.         */
    
  20.         int ButtonA = SDL_GameControllerGetButton(Controller, SDL_CONTROLLER_BUTTON_A);
    
  21.         int ButtonB = SDL_GameControllerGetButton(Controller, SDL_CONTROLLER_BUTTON_B);
    
  22.         if (ButtonA == 1) {
    
  23.             break;
    
  24.         }
    
  25.         if (ButtonB == 1) {
    
  26.             printf("ButtonB is Down\n");
    
  27.         }
    
  28.     }
    
  29. }
    
  30. else {
    
  31.     printf("the joystick is not a game controller\n");
    
  32. }
    
  33. }