Jump to content
  • Advertisement
Sign in to follow this  
walle

Unable to load a image to a surface in an constructor

This topic is 4832 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

Well the title pretty much describes my problem...the surface isn't loaded in my constructor...maybe wery easy problem...but I have no idea...
paddle::paddle()
{
    img=IMG_Load("data/paddle.png");
    SDL_DisplayFormat(img);
    pos.set(10, 300);
    vel.set(0, 0);
}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Well the title pretty much describes my problem


No it doesnt.

What error message are you getting? Are you sure the picture exists?

Share this post


Link to post
Share on other sites
I'm using SDL and SDL_Image as imageloading liberary...

I don't get any errormessage at compiletime...but when I start the application I get a window that says that the application had to terminate...

Share this post


Link to post
Share on other sites
Quote:
Original post by walle
I'm using SDL and SDL_Image as imageloading liberary...

I don't get any errormessage at compiletime...but when I start the application I get a window that says that the application had to terminate...


Did you try running it in the debugger yet?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Did you call SDL_Init() before that constructor is called?

Share this post


Link to post
Share on other sites
Well, it won't break if the image fails to load - the function will just return NULL. If you're getting an access violation, then your image probably isn't loading correctly.

The second problem is your use of SDL_DisplayFormat - it isn't doing anything.
SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface)
SDL_DisplayFormat creates a new surface, which it returns a pointer to. You're just calling it and not saving the new surface, so its doing nothing I've no idea whether or not it destroys the old surface (probably not), but you'll want to fix that.

We need to know where the program crashes, and the error you get.

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!