Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram shuts down immediately SDL
    primarykey
    data
    text
    <p>When I run this code (from the Lazy Foo SDL tutorial) the program immediately shuts down. Why is that? I'm sorry if it gets kind of messy because of the lack of comments, but I thought that it didn't really matter since there were comments on Lazy Foo's post. I get no errors when building it. </p> <pre><code>#include "SDL/SDL_image.h" #include "SDL/SDL.h" #include &lt;string&gt; const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; SDL_Surface *image = NULL; SDL_Surface *screen = NULL; SDL_Event event; SDL_Surface *load_image (std::string filename) { SDL_Surface* loadedImage = NULL; SDL_Surface* optimizedImage = NULL; loadedImage = IMG_Load( filename.c_str()); if(loadedImage != NULL) { optimizedImage = SDL_DisplayFormat (loadedImage); SDL_FreeSurface(loadedImage); } return optimizedImage; } void apply_surface (int x, int y, SDL_Surface* source, SDL_Surface* destination) { SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface (source, NULL, destination, &amp;offset); } bool init() { if (SDL_Init(SDL_INIT_EVERYTHING) == -1) { return false; } screen = SDL_SetVideoMode (SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); if (screen == NULL) { return false; } SDL_WM_SetCaption("Event test", NULL); return true; } bool load_files() { image = load_image ("background.png"); if (image == NULL) { return false; } return true; } void clean_up() { SDL_FreeSurface(image); SDL_Quit(); } int main(int argc, char* args[]) { bool quit = false; if (init() == false) { return 1; } if (load_files() == false) { return 1; } apply_surface(0,0, image, screen); if(SDL_Flip(screen) == -1) { return 1; } while(quit == false) { while (SDL_PollEvent(&amp;event)) { if(event.type == SDL_QUIT) { quit = true; } } } clean_up(); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload