Jump to content
  • Advertisement
Sign in to follow this  
sander242

SDL crash

This topic is 3499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a problem with SDL. I am using the dev c++ compiler and at the line: loadedImage = SDL_LoadBMP(filename.c_str()); my (actually really simple) program just crashes. I am using this line inside a function to load .BMP images: SDL_Surface *load_image(string filename) { SDL_Surface *loadedImage = NULL; SDL_Surface *optimizedImage = NULL; loadedImage = SDL_LoadBMP(filename.c_str()); if (loadedImage != NULL) { optimizedImage = SDL_DisplayFormat(loadedImage); SDL_FreeSurface(loadedImage); } return optimizedImage; } I hope you can help i've tried as much as my limited knowledge about SDL knows, but nothing.

Share this post


Link to post
Share on other sites
Advertisement
There is no reason for your program to crash on that line, unless SDL has a bug in it (which it shouldn't) or you have some memory corruption.

Can you post a minimal, complete program that demonstrates the same behaviour?

Share this post


Link to post
Share on other sites
Show us the code again, in [source] and [/source] tags.
It's most likely something simple.

Do you know what line it is crashing on? A debugger is the way to see this.

Share this post


Link to post
Share on other sites
fine it's going to be long but i'm posting the whole source code:

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

using namespace std;

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

SDL_Surface *screen = NULL;
SDL_Surface *backround = NULL;
SDL_Surface *title = NULL;
SDL_Surface *newProfile = NULL;
SDL_Surface *login = NULL;
SDL_Surface *valu = NULL;

SDL_Event event;

SDL_Surface *load_image(string filename)
{
SDL_Surface *loadedImage = NULL;
SDL_Surface *optimizedImage = NULL;
loadedImage = SDL_LoadBMP(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, &offset);
}
int main( int argc, char* args[] )
{
bool quit = false;

if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
if (screen == NULL)
{
return 1;
}
SDL_WM_SetCaption("window",NULL);
backround = load_image("backround.bmp");
if (backround == NULL)
{return false;}

title = load_image("title.bmp");
if (title == NULL)
{return false;}

newProfile = load_image("newprofile.bmp");
if (newProfile == NULL)
{return false;}

login = load_image("login.bmp");
if (login == NULL)
{return false;}

valu = load_image("valu.bmp");
if (valu == NULL)
{return false;}

apply_surface(0,0,backround,screen);
apply_surface(147,53,title,screen);
apply_surface(195,236,newProfile,screen);
apply_surface(195,299,login,screen);
apply_surface(195,361,valu,screen);
if(SDL_Flip(screen) == -1)
{
cout << "Could not update window";
system("PAUSE");
return 1;
}
while(quit == false)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{ quit = true;}
}
}
SDL_FreeSurface(backround);
SDL_FreeSurface(title);
SDL_FreeSurface(newProfile);
SDL_FreeSurface(login);
SDL_FreeSurface(valu);

SDL_Quit();
return 0;
}

As you can see its a really simple profram written to display 3 smaller images on one big backround waiting for replies

Share this post


Link to post
Share on other sites
I found the problem and the wonder is i found it myself.
i'm so sry i wasted youre time, but i have to learn game programming on my own wothout help.
For anyone who cares the problem was a typo that didnt pass as a compiler error.
I fixed the line when i pasted into the reply window.
it was the line:

valu = load_image("valu.bmp");

i had

valu = load_image("quit.bmp");

agian very sry and thx for the replies.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!