I'm currently learning to code on SDL while using C++ as my base programming language.
So basically, what happens is, I have a piece of code with a loop in it, which will display an image till the loop starts again. The loop is 5 seconds long and the program has an iterator i set to 0 which increases with each loop until it gets to five, when it exits the loop via break. Then SDL quits as expected and the program is done running.
There are no compilation errors, just FYI. When I run the program, the main loop is run one single time and then the programs appears to close it self, printing on my Terminal window a message that says "Segmentation fault (core dumped)".
What does this mean, and what can be done to not make it happen? Thanks in advanced.
EDIT: The code is this one, sorry for not having written before. I'm writing it by memory as I'm currently not at home.
#include <iostream>
#include <SDL.h>
int main( int argc, char** argv )
{
SDL_Surface* media;
SDL_Surface* window;
int i = 0;
SDL_Init( SDL_INIT_EVERYTHING );
window = SDL_SetVideoMode( 1920, 1080, 32, SDL_SWSURFACE );
media = SDL_LoadBMP( "xD.bmp" );
while( true )
{
SDL_BlitSurface( media, NULL, window, NULL );
SDL_Delay( 5000 );
if( i == 5 )
{
break;
}
i++;
}
SDL_FreeSurface( media );
SDL_Quit( );
return 0;
}
EDIT 2: The previous if (i=5) was a typographical and has been corrected.
EDIT 3: I've arrived home and checked my code. I didn't type if (i=5)
, so I'm happy cause that's quite a stupid error. I've also tried lowering the window's size with no success, so we are back to the main problem.
Also, I've tried removing the loop, and it the program is run and at the time of closing gives a segfault, so it's not the loop's fault at least. But this is a bigger problem now. BTW, I'll post the real compiled code, because the one before was written by memory.
#include <iostream>
#include <SDL/SDL.h>
int main (int argc, char** argv)
{
SDL_Surface* window;
SDL_Surface* media;
int i;
SDL_Init (SDL_INIT_EVERYTHING);
window = SDL_SetVideoMode (2058, 1152, 32, SDL_SWSURFACE);
media = SDL_LoadBMP("xD.bmp");
while (true)
{
i++;
SDL_BlitSurface(media, NULL, window, NULL);
SDL_Flip(window);
SDL_Delay(5000);
SDL_FreeSurface(media);
if (i==5)
{
break;
}
}
SDL_FreeSurface(media);
SDL_Quit();
return 0;
}
I just hope this is only happenning to me cause it's a pretty messed up thing to fix. Peace, fellows.