Help! SDL program crashing on me***Fixed***

Started by
14 comments, last by willthiswork89 18 years, 4 months ago
Can anyone tell me what this does?

filename.c_str()

i dont understand what c_str is?
Advertisement
Quote:Original post by willthiswork89
Can anyone tell me what this does?

filename.c_str()

i dont understand what c_str is?


A C++ string is an object, which, IIRC is a dynamic char array (don't quote me on this [grin]). It has member functions. For example, like c_str(). c_str in a string instance would return the C-style string, or (I think it's a const) a char array. So simple you're modifying it with a normal C++ string, but you can use it like a C - style string with c_str().

Anyways, yes, do check that your surfaces aren't null.

@rip-off:
I just looked at his code... He really does that? Maybe he edited his post...
c_str() returns a C-stype const char* Pointer to the string data.
baumep
i put it all into one and now the screen if just black the image wont show up...i dont get wtf is going on....

heres my code if anyone can help out...sorry im really new to sdl lol

#include <SDL/SDL.h>#include <SDL/SDL_image.h>#include <string>using namespace std;#define SWIDTH 640#define SHEIGHT 480#define BPP 32SDL_Surface *image = NULL;SDL_Surface *screen = NULL;SDL_Event event;SDL_Surface *load_image(string filename){SDL_Surface *temp = NULL;SDL_Surface *final = NULL;temp = SDL_LoadBMP(filename.c_str());if(temp != NULL){final = SDL_DisplayFormat(temp);SDL_FreeSurface(temp);}else{ SDL_Quit(); }return final;}void apply_surface(int x,int y, SDL_Surface *source, SDL_Surface *destination){     SDL_Rect ofs;          ofs.x = x;     ofs.y = y;          SDL_BlitSurface(source,NULL,destination,&ofs);}bool init(){     if(SDL_Init(SDL_INIT_EVERYTHING) == -1)     {     return false;     }     screen = SDL_SetVideoMode(SWIDTH,SHEIGHT,BPP,SDL_SWSURFACE);          if(screen == NULL)     {     return false;     }          SDL_WM_SetCaption("Shh Event Driving",NULL);          return true;}bool load_files(){     image = load_image("hello_world.bmp");          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)    {    while(SDL_PollEvent(&event))    {    if(event.type == SDL_QUIT)    quit = true;}}clean_up();return 0;}


everything compiles.. AND runs just no actual images being shown
int main(int argc, char* args[]){    bool quit = false;        if(init() == false)    {        return 1;    }        /*    i added the "()" here after the identifier load_images    you are comparing a functions address with false   its odd yes but it compiles and will run    */    if(load_files() == false)    {        return 1;    }        apply_surface(0,0,image,screen);        if(SDL_Flip(screen) == -1)    {        return 1;    }        while(!quit)    {       while(SDL_PollEvent(&event))       {       if(event.type == SDL_QUIT)          quit = true;       }    }   clean_up();   return 0;}


note the comment above load files call
you know i would have never seen that for months looking at it... lmao thanks man

This topic is closed to new replies.

Advertisement