SDL2 window opens for a few seconds and closes

My SDL2 window opens and closes immediately. But the code still runs.

Here’s a link to the Github page with my code:
And here’s the git repo itself if you want to clone it

Why does the window close, but the code still runs in the while loop?

I simplified my code and posted my question on StackOverflow: