SDL2 is just not working (bmp not displaying).

I’m on ArchLinux (with X11, if that matters), just started learning SDL2. Everything compiles and no errors after running. It’s just that the bmp is not displayed. I literally have no idea why this is not working. This code is derived from Lazy Foo’s SDL2 tutorial. This is my code (c++):

#include <SDL2/SDL.h>
#include <iostream>

#define SCREEN_WIDTH  640
#define SCREEN_HEIGHT 480

SDL_Window *window;
SDL_Surface *surface;

SDL_Surface *bmp;

void init()
{
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        std::cerr << "SDL could not start! SDL error: " << SDL_GetError() << "\n";
        exit(EXIT_FAILURE);
    }
    window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    if (window == NULL) {
        std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << "\n";
        exit(EXIT_FAILURE);
    }
    surface = SDL_GetWindowSurface(window);
}
void loadMedia()
{
    bmp = SDL_LoadBMP("helloworld.bmp");
    if (bmp == NULL) {
        std::cerr << "Unable to load image! SDL_Error: " << SDL_GetError() << "\n"; 
        exit(EXIT_FAILURE);
    }
}
void end()
{
    SDL_FreeSurface(bmp);
    bmp = NULL;
    SDL_DestroyWindow(window);
    window = NULL;
    SDL_Quit();
}

int main(void)
{
    init();
    loadMedia();
    SDL_BlitSurface(bmp, NULL, surface, NULL);
    SDL_UpdateWindowSurface(window);
    SDL_Delay(5000);
    end();
    return 0;
}

You need to handle events in order for the window to display properly.

Yes, it’s an oddity at the OS level–I would guess it’s intended to make sure that anything with a window can respond to kill signals, the little x in the upper right corner of the window, etc. But in any case, there’s no workaround. This means you’ll need to call SDL_PollEvent() in a loop. You can find lots of tutorials for this online. I don’t know if you technically need to do anything with the events you receive for it to display an image, but there’s generally no reason not to, for a windowed application. If nothing else, you should check for SDL_QuitEvent (user clicks the x) and halt execution.

Also note that while lazyfoo is a great tutorial, it is pretty out of date, so there are a few things like this that aren’t accurate anymore.

Ok thanks it works now got it working.